Example #1
0
def testbasic():
    cd = os.path.realpath('')
    WVPASS(cd)
    sd = os.path.realpath('t/sampledata')
    WVPASSEQ(index.realpath('t/sampledata'), cd + '/t/sampledata')
    WVPASSEQ(os.path.realpath('t/sampledata/x'), sd + '/x')
    WVPASSEQ(os.path.realpath('t/sampledata/etc'), os.path.realpath('/etc'))
    WVPASSEQ(index.realpath('t/sampledata/etc'), sd + '/etc')
Example #2
0
def update_index(path):
    ri = index.Reader(indexfile)
    wi = index.Writer(indexfile)
    rig = MergeGetter(ri)
    
    rpath = index.realpath(path)
    st = os.lstat(rpath)
    if opt.xdev:
        xdev = st.st_dev
    else:
        xdev = None
    f = OsFile('.')
    if rpath[-1] == '/':
        rpath = rpath[:-1]
    (dir, name) = os.path.split(rpath)
    dir = slashappend(dir)
    if stat.S_ISDIR(st.st_mode) and (not rpath or rpath[-1] != '/'):
        name += '/'
        can_delete_siblings = True
    else:
        can_delete_siblings = False
    OsFile(dir or '/').fchdir()
    dirty = handle_path(rig, wi, dir, name, st, xdev, can_delete_siblings)

    # make sure all the parents of the updated path exist and are invalidated
    # if appropriate.
    while 1:
        (rpath, junk) = os.path.split(rpath)
        if not rpath:
            break
        elif rpath == '/':
            p = rpath
        else:
            p = rpath + '/'
        while rig.cur and rig.cur.name > p:
            #log('FINISHING: %r path=%r d=%r\n' % (rig.cur.name, p, dirty))
            rig.next()
        if rig.cur and rig.cur.name == p:
            if dirty:
                rig.cur.flags &= ~index.IX_HASHVALID
                rig.cur.repack()
        else:
            wi.add(p, os.lstat(p))
        if p == '/':
            break
    
    f.fchdir()
    ri.save()
    if wi.count:
        mi = index.Writer(indexfile)
        merge_indexes(mi, ri, wi.new_reader())
        ri.close()
        mi.close()
    wi.abort()
Example #3
0
def handle_path(ri, wi, dir, name, pst, xdev, can_delete_siblings):
    hashgen = None
    if opt.fake_valid:
        def hashgen(name):
            return (0, index.FAKE_SHA)
    
    dirty = 0
    path = dir + name
    #log('handle_path(%r,%r)\n' % (dir, name))
    if stat.S_ISDIR(pst.st_mode):
        if opt.verbose == 1: # log dirs only
            sys.stdout.write('%s\n' % path)
            sys.stdout.flush()
        try:
            OsFile(name).fchdir()
        except OSError, e:
            add_error(Exception('in %s: %s' % (dir, str(e))))
            return 0
        try:
            try:
                ld = os.listdir('.')
                #log('* %r: %r\n' % (name, ld))
            except OSError, e:
                add_error(Exception('in %s: %s' % (path, str(e))))
                return 0
            lds = []
            for p in ld:
                try:
                    st = os.lstat(p)
                except OSError, e:
                    add_error(Exception('in %s: %s' % (path, str(e))))
                    continue
                if xdev != None and st.st_dev != xdev:
                    log('Skipping %r: different filesystem.\n' 
                        % index.realpath(p))
                    continue
                if stat.S_ISDIR(st.st_mode):
                    p = slashappend(p)
                lds.append((p, st))