def _add_common(self, path, st): assert (st.st_uid >= 0) assert (st.st_gid >= 0) self.size = st.st_size self.uid = st.st_uid self.gid = st.st_gid self.atime = st.st_atime self.mtime = st.st_mtime self.ctime = st.st_ctime self.user = self.group = '' entry = pwd_from_uid(st.st_uid) if entry: self.user = entry.pw_name entry = grp_from_gid(st.st_gid) if entry: self.group = entry.gr_name self.mode = st.st_mode # Only collect st_rdev if we might need it for a mknod() # during restore. On some platforms (i.e. kFreeBSD), it isn't # stable for other file types. For example "cp -a" will # change it for a plain file. if stat.S_ISCHR(st.st_mode) or stat.S_ISBLK(st.st_mode): self.rdev = st.st_rdev else: self.rdev = 0
def _add_common(self, path, st): self.uid = st.st_uid self.gid = st.st_gid self.rdev = st.st_rdev self.atime = st.st_atime self.mtime = st.st_mtime self.ctime = st.st_ctime self.user = self.group = '' entry = pwd_from_uid(st.st_uid) if entry: self.user = entry.pw_name entry = grp_from_gid(st.st_gid) if entry: self.group = entry.gr_name self.mode = st.st_mode
def _add_common(self, path, st): self.uid = st.st_uid self.gid = st.st_gid self.atime = st.st_atime self.mtime = st.st_mtime self.ctime = st.st_ctime self.user = self.group = "" entry = pwd_from_uid(st.st_uid) if entry: self.user = entry.pw_name entry = grp_from_gid(st.st_gid) if entry: self.group = entry.gr_name self.mode = st.st_mode # Only collect st_rdev if we might need it for a mknod() # during restore. On some platforms (i.e. kFreeBSD), it isn't # stable for other file types. For example "cp -a" will # change it for a plain file. if stat.S_ISCHR(st.st_mode) or stat.S_ISBLK(st.st_mode): self.rdev = st.st_rdev else: self.rdev = 0
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, 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 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, e: if e.errno == errno.EPERM: add_error('lchown: %s' % e) else: raise if _have_lchmod:
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))