def test_metadata_method(): tmpdir = tempfile.mkdtemp(prefix="bup-tmetadata-") try: bup_dir = tmpdir + "/bup" data_path = tmpdir + "/foo" os.mkdir(data_path) ex("touch", data_path + "/file") ex("ln", "-s", "file", data_path + "/symlink") test_time1 = 13 * 1000000000 test_time2 = 42 * 1000000000 utime(data_path + "/file", (0, test_time1)) lutime(data_path + "/symlink", (0, 0)) utime(data_path, (0, test_time2)) ex(bup_path, "-d", bup_dir, "init") ex(bup_path, "-d", bup_dir, "index", "-v", data_path) ex(bup_path, "-d", bup_dir, "save", "-tvvn", "test", data_path) git.check_repo_or_die(bup_dir) top = vfs.RefList(None) n = top.lresolve("/test/latest" + realpath(data_path)) m = n.metadata() WVPASS(m.mtime == test_time2) WVPASS(len(n.subs()) == 2) WVPASS(n.name == "foo") WVPASS(set([x.name for x in n.subs()]) == set(["file", "symlink"])) for sub in n: if sub.name == "file": m = sub.metadata() WVPASS(m.mtime == test_time1) elif sub.name == "symlink": m = sub.metadata() WVPASS(m.mtime == 0) finally: subprocess.call(["rm", "-rf", tmpdir])
def test_metadata_method(): tmpdir = tempfile.mkdtemp(prefix='bup-tmetadata-') try: bup_dir = tmpdir + '/bup' data_path = tmpdir + '/foo' os.mkdir(data_path) ex('touch', data_path + '/file') ex('ln', '-s', 'file', data_path + '/symlink') test_time1 = 13 * 1000000000 test_time2 = 42 * 1000000000 utime(data_path + '/file', (0, test_time1)) lutime(data_path + '/symlink', (0, 0)) utime(data_path, (0, test_time2)) ex(bup_path, '-d', bup_dir, 'init') ex(bup_path, '-d', bup_dir, 'index', '-v', data_path) ex(bup_path, '-d', bup_dir, 'save', '-tvvn', 'test', data_path) git.check_repo_or_die(bup_dir) top = vfs.RefList(None) n = top.lresolve('/test/latest' + realpath(data_path)) m = n.metadata() WVPASS(m.mtime == test_time2) WVPASS(len(n.subs()) == 2) WVPASS(n.name == 'foo') WVPASS(set([x.name for x in n.subs()]) == set(['file', 'symlink'])) for sub in n: if sub.name == 'file': m = sub.metadata() WVPASS(m.mtime == test_time1) elif sub.name == 'symlink': m = sub.metadata() WVPASS(m.mtime == 0) finally: subprocess.call(['rm', '-rf', tmpdir])
def test_metadata_method(): initial_failures = wvfailure_count() tmpdir = tempfile.mkdtemp(dir=bup_tmp, prefix='bup-tmetadata-') bup_dir = tmpdir + '/bup' data_path = tmpdir + '/foo' os.mkdir(data_path) ex('touch', data_path + '/file') ex('ln', '-s', 'file', data_path + '/symlink') test_time1 = 13 * 1000000000 test_time2 = 42 * 1000000000 utime(data_path + '/file', (0, test_time1)) lutime(data_path + '/symlink', (0, 0)) utime(data_path, (0, test_time2)) ex(bup_path, '-d', bup_dir, 'init') ex(bup_path, '-d', bup_dir, 'index', '-v', data_path) ex(bup_path, '-d', bup_dir, 'save', '-tvvn', 'test', data_path) git.check_repo_or_die(bup_dir) top = vfs.RefList(None) n = top.lresolve('/test/latest' + realpath(data_path)) m = n.metadata() WVPASS(m.mtime == test_time2) WVPASS(len(n.subs()) == 2) WVPASS(n.name == 'foo') WVPASS(set([x.name for x in n.subs()]) == set(['file', 'symlink'])) for sub in n: if sub.name == 'file': m = sub.metadata() WVPASS(m.mtime == test_time1) elif sub.name == 'symlink': m = sub.metadata() WVPASS(m.mtime == 0) if wvfailure_count() == initial_failures: subprocess.call(['rm', '-rf', tmpdir])
def test_metadata_method(): with no_lingering_errors(), test_tempdir('bup-tmetadata-') as tmpdir: bup_dir = tmpdir + '/bup' data_path = tmpdir + '/foo' os.mkdir(data_path) ex('touch', data_path + '/file') ex('ln', '-s', 'file', data_path + '/symlink') test_time1 = 13 * 1000000000 test_time2 = 42 * 1000000000 utime(data_path + '/file', (0, test_time1)) lutime(data_path + '/symlink', (0, 0)) utime(data_path, (0, test_time2)) ex(bup_path, '-d', bup_dir, 'init') ex(bup_path, '-d', bup_dir, 'index', '-v', data_path) ex(bup_path, '-d', bup_dir, 'save', '-tvvn', 'test', data_path) git.check_repo_or_die(bup_dir) top = vfs.RefList(None) n = top.lresolve('/test/latest' + resolve_parent(data_path)) m = n.metadata() WVPASS(m.mtime == test_time2) WVPASS(len(n.subs()) == 2) WVPASS(n.name == 'foo') WVPASS(set([x.name for x in n.subs()]) == set(['file', 'symlink'])) for sub in n: if sub.name == 'file': m = sub.metadata() WVPASS(m.mtime == test_time1) elif sub.name == 'symlink': m = sub.metadata() WVPASS(m.mtime == 0)
def test_metadata_method(tmpdir): bup_dir = tmpdir + b'/bup' data_path = tmpdir + b'/foo' os.mkdir(data_path) ex(b'touch', data_path + b'/file') ex(b'ln', b'-s', b'file', data_path + b'/symlink') test_time1 = 13 * 1000000000 test_time2 = 42 * 1000000000 utime(data_path + b'/file', (0, test_time1)) lutime(data_path + b'/symlink', (0, 0)) utime(data_path, (0, test_time2)) ex(bup_path, b'-d', bup_dir, b'init') ex(bup_path, b'-d', bup_dir, b'index', b'-v', data_path) ex(bup_path, b'-d', bup_dir, b'save', b'-tvvn', b'test', data_path) repo = LocalRepo(bup_dir) resolved = vfs.resolve(repo, b'/test/latest' + resolve_parent(data_path), follow=False) leaf_name, leaf_item = resolved[-1] m = leaf_item.meta WVPASS(m.mtime == test_time2) WVPASS(leaf_name == b'foo') contents = tuple(vfs.contents(repo, leaf_item)) WVPASS(len(contents) == 3) WVPASSEQ(frozenset(name for name, item in contents), frozenset((b'.', b'file', b'symlink'))) for name, item in contents: if name == b'file': m = item.meta WVPASS(m.mtime == test_time1) elif name == b'symlink': m = item.meta WVPASSEQ(m.symlink_target, b'file') WVPASSEQ(m.size, 4) WVPASSEQ(m.mtime, 0)
def _apply_common_rec(self, path, restore_numeric_ids=False): # FIXME: S_ISDOOR, S_IFMPB, S_IFCMP, S_IFNWK, ... see stat(2). # EACCES errors at this stage are fatal for the current path. if stat.S_ISLNK(self.mode): try: lutime(path, (self.atime, self.mtime)) except OSError, e: if e.errno == errno.EACCES: raise ApplyError('lutime: %s' % e) else: raise
def test_metadata_method(): with no_lingering_errors(): with test_tempdir('bup-tmetadata-') as tmpdir: bup_dir = tmpdir + '/bup' data_path = tmpdir + '/foo' os.mkdir(data_path) ex('touch', data_path + '/file') ex('ln', '-s', 'file', data_path + '/symlink') test_time1 = 13 * 1000000000 test_time2 = 42 * 1000000000 utime(data_path + '/file', (0, test_time1)) lutime(data_path + '/symlink', (0, 0)) utime(data_path, (0, test_time2)) ex(bup_path, '-d', bup_dir, 'init') ex(bup_path, '-d', bup_dir, 'index', '-v', data_path) ex(bup_path, '-d', bup_dir, 'save', '-tvvn', 'test', data_path) git.check_repo_or_die(bup_dir) repo = LocalRepo() resolved = vfs.resolve(repo, '/test/latest' + resolve_parent(data_path), follow=False) leaf_name, leaf_item = resolved[-1] m = leaf_item.meta WVPASS(m.mtime == test_time2) WVPASS(leaf_name == 'foo') contents = tuple(vfs.contents(repo, leaf_item)) WVPASS(len(contents) == 3) WVPASSEQ(frozenset(name for name, item in contents), frozenset(('.', 'file', 'symlink'))) for name, item in contents: if name == 'file': m = item.meta WVPASS(m.mtime == test_time1) elif name == 'symlink': m = item.meta WVPASSEQ(m.symlink_target, 'file') WVPASSEQ(m.size, 4) WVPASSEQ(m.mtime, 0)
def _apply_common_rec(self, path, restore_numeric_ids=False): if not self.mode: raise ApplyError('no metadata - cannot apply to ' + path_msg(path)) # FIXME: S_ISDOOR, S_IFMPB, S_IFCMP, S_IFNWK, ... see stat(2). # EACCES errors at this stage are fatal for the current path. if lutime and stat.S_ISLNK(self.mode): try: lutime(path, (self.atime, self.mtime)) except OSError as e: if e.errno == errno.EACCES: raise ApplyError('lutime: %s' % e) else: raise else: try: utime(path, (self.atime, self.mtime)) except OSError as e: if e.errno == errno.EACCES: raise ApplyError('utime: %s' % e) else: raise uid = gid = -1 # By default, do nothing. if is_superuser(): if self.uid is not None: uid = self.uid if self.gid is not None: gid = self.gid if not restore_numeric_ids: if self.uid != 0 and self.user: entry = pwd_from_name(self.user) if entry: uid = entry.pw_uid if self.gid != 0 and self.group: entry = grp_from_name(self.group) if entry: gid = entry.gr_gid else: # not superuser - only consider changing the group/gid user_gids = os.getgroups() if self.gid in user_gids: gid = self.gid if not restore_numeric_ids and self.gid != 0: # The grp might not exist on the local system. grps = filter(None, [grp_from_gid(x) for x in user_gids]) if self.group in [x.gr_name for x in grps]: g = grp_from_name(self.group) if g: gid = g.gr_gid if uid != -1 or gid != -1: try: os.lchown(path, uid, gid) except OSError as e: if e.errno == errno.EPERM: add_error('lchown: %s' % e) elif sys.platform.startswith('cygwin') \ and e.errno == errno.EINVAL: add_error('lchown: unknown uid/gid (%d/%d) for %s' % (uid, gid, path_msg(path))) else: raise if _have_lchmod: try: os.lchmod(path, stat.S_IMODE(self.mode)) except OSError as e: # - "Function not implemented" # - "Operation not supported" might be generated by glibc if e.errno in (errno.ENOSYS, errno.EOPNOTSUPP): pass else: raise elif not stat.S_ISLNK(self.mode): os.chmod(path, stat.S_IMODE(self.mode))
def _apply_common_rec(self, path, restore_numeric_ids=False): if not self.mode: raise ApplyError('no metadata - cannot apply to ' + path) # FIXME: S_ISDOOR, S_IFMPB, S_IFCMP, S_IFNWK, ... see stat(2). # EACCES errors at this stage are fatal for the current path. if lutime and stat.S_ISLNK(self.mode): try: lutime(path, (self.atime, self.mtime)) except OSError as e: if e.errno == errno.EACCES: raise ApplyError('lutime: %s' % e) else: raise else: try: utime(path, (self.atime, self.mtime)) except OSError as e: if e.errno == errno.EACCES: raise ApplyError('utime: %s' % e) else: raise uid = gid = -1 # By default, do nothing. if is_superuser(): uid = self.uid gid = self.gid if not restore_numeric_ids: if self.uid != 0 and self.user: entry = pwd_from_name(self.user) if entry: uid = entry.pw_uid if self.gid != 0 and self.group: entry = grp_from_name(self.group) if entry: gid = entry.gr_gid else: # not superuser - only consider changing the group/gid user_gids = os.getgroups() if self.gid in user_gids: gid = self.gid if not restore_numeric_ids and self.gid != 0: # The grp might not exist on the local system. grps = filter(None, [grp_from_gid(x) for x in user_gids]) if self.group in [x.gr_name for x in grps]: g = grp_from_name(self.group) if g: gid = g.gr_gid if uid != -1 or gid != -1: try: os.lchown(path, uid, gid) except OSError as e: if e.errno == errno.EPERM: add_error('lchown: %s' % e) elif sys.platform.startswith('cygwin') \ and e.errno == errno.EINVAL: add_error('lchown: unknown uid/gid (%d/%d) for %s' % (uid, gid, path)) else: raise if _have_lchmod: try: os.lchmod(path, stat.S_IMODE(self.mode)) except errno.ENOSYS: # Function not implemented pass elif not stat.S_ISLNK(self.mode): os.chmod(path, stat.S_IMODE(self.mode))