def filter_extended(self, item): if not self.extended: return True path = item.path if self.xattr: if self.xattr is True: if has_xattrs(path): return True elif any([self.xattr.match(x) for x in has_xattrs(path)]): return True if self.suid or self.sgid and sys.platform != 'win32': if self.suid and item.stat().st_mode & 0o4000: return True if self.sgid and item.stat().st_mode & 0o2000: return True if self.user or self.group: uid, gid = uidgid(path, item.stat(), as_text=False) if self.user and self.user == uid or self.group and self.group == gid: return True if self.owaw: if item.is_dir(): try: tmp_file = os.path.join(path, OWAW_PROBE_NAME) f = open(tmp_file, 'w') f.close() os.unlink(tmp_file) return True except (OSError, IOError): pass elif item.is_file(): try: f = open(path, 'a') f.close() return True except (OSError, IOError): pass if self.newer and item.stat().st_mtime > self.newer: return True if self.older and item.stat().st_mtime < self.older: return True return False
def _stat_to_ls_struct(path, name, _stat, resolve_uidgid=False): if stat.S_ISLNK(_stat.st_mode): try: name += ' -> ' + readlink(path) except: pass try: f_xattrs = has_xattrs(path) except (OSError, IOError): f_xattrs = False if resolve_uidgid: uid, gid = uidgid(path, _stat) else: uid, gid = _stat.st_uid, _stat.st_gid return { T_NAME: name, T_TYPE: mode_to_letter(_stat.st_mode), T_SPEC: special_to_letter(_stat.st_mode), T_MODE: _stat.st_mode, T_UID: uid, T_GID: gid, T_SIZE: _stat.st_size, T_TIMESTAMP: int(_stat.st_mtime), T_HAS_XATTR: bool(f_xattrs) }
def getfilesec(filepath): header = '' if path.isfile(filepath): try: with open(filepath) as fileobj: header = fileobj.read(4096) except IOError: pass filestat = stat(filepath) owner, group, acls = getfileowneracls(filepath) streams = has_xattrs(filepath) link = None try: if islink(filepath): link = readlink(filepath) except (WindowsError, ValueError, OSError, IOError): pass mode = mode_to_letter(filestat.st_mode) extras = { 'ACLs': [unicode(x) for x in acls] if acls else None, 'Streams': streams, 'Link': link } return int(filestat.st_ctime), int(filestat.st_atime), \ int(filestat.st_mtime), filestat.st_size, owner, group, \ header, mode, {k:v for k,v in extras.iteritems() if v}
def getfilesec(filepath): header = '' filepath = path.expanduser(filepath) filepath = path.expandvars(filepath) if path.isfile(filepath): try: with open(filepath) as fileobj: header = fileobj.read(4096) except (OSError, IOError): pass try: filestat = stat(filepath) owner, group, acls = getfileowneracls(filepath) streams = has_xattrs(filepath) link = None except Exception as e: try_exc_utf8(e) raise try: if islink(filepath): link = readlink(filepath) except (WindowsError, ValueError, OSError, IOError): pass mode = mode_to_letter(filestat.st_mode) extras = { 'ACLs': [unicode(x) for x in acls] if acls else None, 'Streams': streams, 'Link': link, 'Version': getfilever(filepath), } certs = getfilecert(filepath) if certs: extras.update(certs) extras.update(getfiletrust(filepath)) return int(filestat.st_ctime), int(filestat.st_atime), \ int(filestat.st_mtime), filestat.st_size, owner, group, \ header, mode, {k:v for k,v in extras.iteritems() if v}