def restore_attrs(self, path, item, symlink=False, fd=None): xattrs = item.get(b'xattrs') if xattrs: for k, v in xattrs.items(): try: xattr.setxattr(fd or path, k, v, follow_symlinks=False) except OSError as e: if e.errno != errno.ENOTSUP: raise uid = gid = None if not self.numeric_owner: uid = user2uid(item[b'user']) gid = group2gid(item[b'group']) uid = item[b'uid'] if uid is None else uid gid = item[b'gid'] if gid is None else gid # This code is a bit of a mess due to os specific differences try: if fd: os.fchown(fd, uid, gid) else: os.lchown(path, uid, gid) except OSError: pass if fd: os.fchmod(fd, item[b'mode']) elif not symlink: os.chmod(path, item[b'mode']) elif has_lchmod: # Not available on Linux os.lchmod(path, item[b'mode']) mtime = bigint_to_int(item[b'mtime']) if fd and utime_supports_fd: # Python >= 3.3 os.utime(fd, None, ns=(mtime, mtime)) elif utime_supports_follow_symlinks: # Python >= 3.3 os.utime(path, None, ns=(mtime, mtime), follow_symlinks=False) elif not symlink: os.utime(path, (mtime / 1e9, mtime / 1e9)) acl_set(path, item, self.numeric_owner) # Only available on OS X and FreeBSD if has_lchflags and b'bsdflags' in item: try: os.lchflags(path, item[b'bsdflags']) except OSError: pass
def restore_attrs(self, path, item, symlink=False, fd=None): xattrs = item.get(b"xattrs") if xattrs: for k, v in xattrs.items(): try: xattr.setxattr(fd or path, k, v, follow_symlinks=False) except OSError as e: if e.errno != errno.ENOTSUP: raise uid = gid = None if not self.numeric_owner: uid = user2uid(item[b"user"]) gid = group2gid(item[b"group"]) uid = item[b"uid"] if uid is None else uid gid = item[b"gid"] if gid is None else gid # This code is a bit of a mess due to os specific differences try: if fd: os.fchown(fd, uid, gid) else: os.lchown(path, uid, gid) except OSError: pass if fd: os.fchmod(fd, item[b"mode"]) elif not symlink: os.chmod(path, item[b"mode"]) elif has_lchmod: # Not available on Linux os.lchmod(path, item[b"mode"]) if fd and utime_supports_fd: # Python >= 3.3 os.utime(fd, None, ns=(item[b"mtime"], item[b"mtime"])) elif utime_supports_fd: # Python >= 3.3 os.utime(path, None, ns=(item[b"mtime"], item[b"mtime"]), follow_symlinks=False) elif not symlink: os.utime(path, (item[b"mtime"] / 10 ** 9, item[b"mtime"] / 10 ** 9)) acl_set(path, item, self.numeric_owner) # Only available on OS X and FreeBSD if has_lchflags and b"bsdflags" in item: try: os.lchflags(path, item[b"bsdflags"]) except OSError: pass
def set_acl(self, path, access=None, default=None, numeric_owner=False): item = {b'acl_access': access, b'acl_default': default} acl_set(path, item, numeric_owner=numeric_owner)
def set_acl(self, path, acl, numeric_owner=False): item = {b'acl_extended': acl} acl_set(path, item, numeric_owner=numeric_owner)
def set_acl(self, path, access=None, default=None): item = {b'acl_access': access, b'acl_default': default} acl_set(path, item)