Ejemplo n.º 1
0
def _slashappend_or_add_error(p, caller):
    """Return p, after ensuring it has a single trailing slash if it names
    a directory, unless there's an OSError, in which case, call
    add_error() and return None."""
    try:
        st = os.lstat(p)
    except OSError as e:
        add_error('%s: %s' % (caller, e))
        return None
    else:
        if stat.S_ISDIR(st.st_mode):
            return slashappend(p)
        return p
Ejemplo n.º 2
0
Archivo: index.py Proyecto: bup/bup
def _slashappend_or_add_error(p, caller):
    """Return p, after ensuring it has a single trailing slash if it names
    a directory, unless there's an OSError, in which case, call
    add_error() and return None."""
    try:
        st = os.lstat(p)
    except OSError as e:
        add_error('%s: %s' % (caller, e))
        return None
    else:
        if stat.S_ISDIR(st.st_mode):
            return slashappend(p)
        return p
Ejemplo n.º 3
0
def reduce_paths(paths):
    xpaths = []
    for p in paths:
        rp = resolve_parent(p)
        try:
            st = os.lstat(rp)
            if stat.S_ISDIR(st.st_mode):
                rp = slashappend(rp)
                p = slashappend(p)
            xpaths.append((rp, p))
        except OSError as e:
            add_error('reduce_paths: %s' % e)
    xpaths.sort()

    paths = []
    prev = None
    for (rp, p) in xpaths:
        if prev and (prev == rp 
                     or (prev.endswith('/') and rp.startswith(prev))):
            continue # already superceded by previous path
        paths.append((rp, p))
        prev = rp
    paths.sort(reverse=True)
    return paths
Ejemplo n.º 4
0
def reduce_paths(paths):
    xpaths = []
    for p in paths:
        rp = resolve_parent(p)
        try:
            st = os.lstat(rp)
            if stat.S_ISDIR(st.st_mode):
                rp = slashappend(rp)
                p = slashappend(p)
            xpaths.append((rp, p))
        except OSError as e:
            add_error('reduce_paths: %s' % e)
    xpaths.sort()

    paths = []
    prev = None
    for (rp, p) in xpaths:
        if prev and (prev == rp or
                     (prev.endswith('/') and rp.startswith(prev))):
            continue  # already superceded by previous path
        paths.append((rp, p))
        prev = rp
    paths.sort(reverse=True)
    return paths
Ejemplo n.º 5
0
Archivo: index.py Proyecto: lelutin/bup
def reduce_paths(paths):
    xpaths = []
    for p in paths:
        rp = _slashappend_or_add_error(resolve_parent(p), "reduce_paths")
        if rp:
            xpaths.append((rp, slashappend(p) if rp.endswith("/") else p))
    xpaths.sort()

    paths = []
    prev = None
    for (rp, p) in xpaths:
        if prev and (prev == rp or (prev.endswith("/") and rp.startswith(prev))):
            continue  # already superceded by previous path
        paths.append((rp, p))
        prev = rp
    paths.sort(reverse=True)
    return paths
Ejemplo n.º 6
0
def reduce_paths(paths):
    xpaths = []
    for p in paths:
        rp = _slashappend_or_add_error(resolve_parent(p), 'reduce_paths')
        if rp:
            xpaths.append((rp, slashappend(p) if rp.endswith(b'/') else p))
    xpaths.sort()

    paths = []
    prev = None
    for (rp, p) in xpaths:
        if prev and (prev == rp or
                     (prev.endswith(b'/') and rp.startswith(prev))):
            continue  # already superceded by previous path
        paths.append((rp, p))
        prev = rp
    paths.sort(reverse=True)
    return paths