Python stat.S_IFDIR Examples
The following are 30
code examples of stat.S_IFDIR().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
stat
, or try the search function
.
Example #1
Source File: directory.py From king-phisher-plugins with BSD 3-Clause "New" or "Revised" License | 6 votes |
def render_python_value(value): if not isinstance(value, int): return if value & stat.S_IFDIR: perm = 'd' else: perm = '-' perm += 'r' if value & stat.S_IRUSR else '-' perm += 'w' if value & stat.S_IWUSR else '-' if value & stat.S_ISUID: perm += 's' if value & stat.S_IXUSR else 'S' else: perm += 'x' if value & stat.S_IXUSR else '-' perm += 'r' if value & stat.S_IRGRP else '-' perm += 'w' if value & stat.S_IWGRP else '-' if value & stat.S_ISGID: perm += 's' if value & stat.S_IXGRP else 'S' else: perm += 'x' if value & stat.S_IXGRP else '-' perm += 'r' if value & stat.S_IROTH else '-' perm += 'w' if value & stat.S_IWOTH else '-' perm += 'x' if value & stat.S_IXOTH else '-' return perm
Example #2
Source File: index.py From gitfs with Apache License 2.0 | 6 votes |
def getattr(self, path, fh=None): """ Returns a dictionary with keys identical to the stat C structure of stat(2). st_atime, st_mtime and st_ctime should be floats. NOTE: There is an incombatibility between Linux and Mac OS X concerning st_nlink of directories. Mac OS X counts all files inside the directory, while Linux counts only the subdirectories. """ if path != "/": raise FuseOSError(ENOENT) attrs = super(IndexView, self).getattr(path, fh) attrs.update({"st_mode": S_IFDIR | 0o555, "st_nlink": 2}) return attrs
Example #3
Source File: index.py From git-in-python with GNU Lesser General Public License v2.1 | 6 votes |
def do_commit(self): tree = {} for path, property in self.entries.iteritems(): t = tree path_arr = path.split('/') for path_ele in path_arr[:-1]: t = t.setdefault(path_ele, {}) t = t.setdefault(path_arr[-1], (property['mode'], property['sha1'])) def _build_tree(path): dir_arr = [] file_arr = [] for name, entry in path.iteritems(): if isinstance(entry, dict): mode = stat.S_IFDIR sha1 = _build_tree(entry).sha1 dir_arr.append({'name':name, 'mode':mode, 'sha1':sha1}) else: (mode, sha1) = entry file_arr.append({'name':name, 'mode':mode, 'sha1':sha1}) newtree = Tree(sorted(dir_arr,key = lambda x:x['name']) + sorted(file_arr,key = lambda x:x['name'])) write_to_file(newtree.path, newtree.content) return newtree return _build_tree(tree)
Example #4
Source File: DropBox.py From stash with MIT License | 6 votes |
def stat(self, name): ap = self.abspath(name) if ap in ("/", "/.", "./", "//", ""): bytes = 0 isdir = True else: try: meta = self.client.files_get_metadata(ap) except dropbox.exceptions.ApiError as e: raise OperationFailure(e.message) if isinstance(meta, (dropbox.files.FolderMetadata, dropbox.sharing.SharedFolderMetadata)): bytes = 0 isdir = True else: bytes = meta.size isdir = False type_ = (stat.S_IFDIR if isdir else stat.S_IFREG) m = calc_mode(type=type_) s = make_stat(size=bytes, mode=m) return s
Example #5
Source File: zip.py From stash with MIT License | 6 votes |
def stat(self, name): ap = self.abspath(name) self.log("stat: {ap}\n".format(ap=ap)) isdir = self.isdir(name) isfile = self.isfile(name) if not (isdir or isfile): self.log("stat-target not found.\n") raise errors.OperationFailure("Not found!") if isdir: size = 1 mtime = None else: zipinfo = self.zf.getinfo(ap) size = zipinfo.file_size timestamp = zipinfo.date_time dt = datetime.datetime(*timestamp) mtime = (dt - datetime.datetime(1970, 1, 1)).total_seconds() type_ = (stat.S_IFREG if isfile else stat.S_IFDIR) mode = base.calc_mode(type=type_) self.log("stat return\n") return base.make_stat(size=size, mtime=mtime, ctime=mtime, mode=mode)
Example #6
Source File: mkfs.py From s3ql with GNU General Public License v3.0 | 6 votes |
def init_tables(conn): # Insert root directory now_ns = time_ns() conn.execute("INSERT INTO inodes (id,mode,uid,gid,mtime_ns,atime_ns,ctime_ns,refcount) " "VALUES (?,?,?,?,?,?,?,?)", (ROOT_INODE, stat.S_IFDIR | stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | stat.S_IRGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IXOTH, os.getuid(), os.getgid(), now_ns, now_ns, now_ns, 1)) # Insert control inode, the actual values don't matter that much conn.execute("INSERT INTO inodes (id,mode,uid,gid,mtime_ns,atime_ns,ctime_ns,refcount) " "VALUES (?,?,?,?,?,?,?,?)", (CTRL_INODE, stat.S_IFREG | stat.S_IRUSR | stat.S_IWUSR, 0, 0, now_ns, now_ns, now_ns, 42)) # Insert lost+found directory inode = conn.rowid("INSERT INTO inodes (mode,uid,gid,mtime_ns,atime_ns,ctime_ns,refcount) " "VALUES (?,?,?,?,?,?,?)", (stat.S_IFDIR | stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR, os.getuid(), os.getgid(), now_ns, now_ns, now_ns, 1)) name_id = conn.rowid('INSERT INTO names (name, refcount) VALUES(?,?)', (b'lost+found', 1)) conn.execute("INSERT INTO contents (name_id, inode, parent_inode) VALUES(?,?,?)", (name_id, inode, ROOT_INODE))
Example #7
Source File: repository.py From gitfs with Apache License 2.0 | 6 votes |
def get_git_object_default_stats(self, ref, path): types = { GIT_FILEMODE_LINK: {"st_mode": S_IFLNK | 0o444}, GIT_FILEMODE_TREE: {"st_mode": S_IFDIR | 0o555, "st_nlink": 2}, GIT_FILEMODE_BLOB: {"st_mode": S_IFREG | 0o444}, GIT_FILEMODE_BLOB_EXECUTABLE: {"st_mode": S_IFREG | 0o555}, } if path == "/": return types[GIT_FILEMODE_TREE] obj_type = self.get_git_object_type(ref, path) if obj_type is None: return obj_type stats = types[obj_type] if obj_type in [GIT_FILEMODE_BLOB, GIT_FILEMODE_BLOB_EXECUTABLE]: stats["st_size"] = self.get_blob_size(ref, path) return stats
Example #8
Source File: pathio.py From aioftp with Apache License 2.0 | 6 votes |
def stat(self, path): node = self.get_node(path) if node is None: raise FileNotFoundError else: if node.type == "file": size = len(node.content.getbuffer()) mode = stat.S_IFREG | 0o666 else: size = 0 mode = stat.S_IFDIR | 0o777 return MemoryPathIO.Stats( size, node.ctime, node.mtime, 1, mode, )
Example #9
Source File: mount.py From python-ntfs with Apache License 2.0 | 6 votes |
def getattr(self, path, fh=None): (uid, gid, pid) = fuse_get_context() entry = self._get_path_entry(path) if entry.is_directory(): mode = (stat.S_IFDIR | PERMISSION_ALL_READ) nlink = 2 else: mode = (stat.S_IFREG | PERMISSION_ALL_READ) nlink = 1 return { "st_atime": unixtimestamp(entry.get_si_accessed_timestamp()), "st_ctime": unixtimestamp(entry.get_si_changed_timestamp()), "st_crtime": unixtimestamp(entry.get_si_created_timestamp()), "st_mtime": unixtimestamp(entry.get_si_modified_timestamp()), "st_size": entry.get_size(), "st_uid": uid, "st_gid": gid, "st_mode": mode, "st_nlink": nlink, }
Example #10
Source File: t3_fsck.py From s3ql with GNU General Public License v3.0 | 6 votes |
def test_unix_nomode_dir(self): perms = stat.S_IRUSR | stat.S_IWUSR | stat.S_IROTH | stat.S_IRGRP stamp = time_ns() inode = self.db.rowid("INSERT INTO inodes (mode,uid,gid,mtime_ns,atime_ns,ctime_ns,refcount) " "VALUES (?,?,?,?,?,?,?)", (perms, os.getuid(), os.getgid(), stamp, stamp, stamp, 1)) inode2 = self.db.rowid("INSERT INTO inodes (mode,uid,gid,mtime_ns,atime_ns,ctime_ns,refcount) " "VALUES (?,?,?,?,?,?,?)", (perms | stat.S_IFREG, os.getuid(), os.getgid(), stamp, stamp, stamp, 1)) self._link(b'test-entry', inode) self._link(b'subentry', inode2, inode) self.assert_fsck(self.fsck.check_unix) newmode = self.db.get_val('SELECT mode FROM inodes WHERE id=?', (inode,)) self.assertEqual(stat.S_IMODE(newmode), perms) self.assertEqual(stat.S_IFMT(newmode), stat.S_IFDIR)
Example #11
Source File: test_commit.py From gitfs with Apache License 2.0 | 6 votes |
def test_getattr_with_simple_path(self): mocked_repo = MagicMock() mocked_commit = MagicMock() stats = {"st_mode": S_IFDIR | 0o555, "st_nlink": 2} mocked_commit.tree = "tree" mocked_commit.commit_time = "now+1" mocked_repo.revparse_single.return_value = mocked_commit mocked_repo.get_git_object_default_stats.return_value = stats view = CommitView( repo=mocked_repo, commit_sha1="sha1", mount_time="now", uid=1, gid=1 ) result = view.getattr("/", 1) asserted_result = { "st_uid": 1, "st_gid": 1, "st_mtime": "now+1", "st_ctime": "now+1", "st_mode": S_IFDIR | 0o555, "st_nlink": 2, } assert result == asserted_result
Example #12
Source File: sn_fuse.py From standardnotes-fs with GNU General Public License v3.0 | 6 votes |
def __init__(self, sn_api, sync_sec, ext, path='.'): self.item_manager = ItemManager(sn_api, ext) self.uid = os.getuid() self.gid = os.getgid() now = datetime.now().timestamp() self.dir_stat = dict(st_mode=(S_IFDIR | DIR_PERMISSIONS), st_ctime=now, st_mtime=now, st_atime=now, st_nlink=2, st_uid=self.uid, st_gid=self.gid) self.note_stat = dict(st_mode=(S_IFREG | FILE_PERMISSIONS), st_ctime=now, st_mtime=now, st_atime=now, st_nlink=1, st_uid=self.uid, st_gid=self.gid) self.sync_sec = sync_sec self.ext = ext self.run_sync = Event() self.stop_sync = Event() self.sync_thread = Thread(target=self._sync_thread)
Example #13
Source File: interface.py From pytest-sftpserver with MIT License | 6 votes |
def stat(self): if self.content_provider.get(self.path) is None: return SFTP_NO_SUCH_FILE mtime = calendar.timegm(datetime.now().timetuple()) sftp_attrs = SFTPAttributes() sftp_attrs.st_size = self.content_provider.get_size(self.path) sftp_attrs.st_uid = 0 sftp_attrs.st_gid = 0 sftp_attrs.st_mode = ( stat.S_IRWXO | stat.S_IRWXG | stat.S_IRWXU | (stat.S_IFDIR if self.content_provider.is_dir(self.path) else stat.S_IFREG) ) sftp_attrs.st_atime = mtime sftp_attrs.st_mtime = mtime sftp_attrs.filename = posixpath.basename(self.path) return sftp_attrs
Example #14
Source File: registry.py From rekall with GNU General Public License v2.0 | 6 votes |
def __init__(self, filename=None, **kwargs): filename = common.FileSpec(filename, filesystem="Reg", path_sep="\\") super(RegistryKeyInformation, self).__init__( filename=filename, **kwargs) self.hive = self.key_name = self.value_name = self.value = "" self.value_type = "REG_NONE" self.st_mode = stat.S_IFDIR path_components = self.filename.components() if not path_components: return # The first component MUST be a hive self.hive = path_components[0] self._hive_handle = KeyHandle(getattr(_winreg, self.hive, None)) if self._hive_handle is None: raise IOError("Unknown hive name %s" % self.hive) # Maybe its a key. try: self._read_key(path_components) except WindowsError: # Nop - maybe its a value then. self._read_value(path_components)
Example #15
Source File: address_space_fuse.py From rekall with GNU General Public License v2.0 | 6 votes |
def getattr(self, path): # The path represents a pid. components = os.path.split(path) if len(components) > 2: return if len(components) == 2 and components[1] in self.tasks: s = make_stat(components[1]) s.st_mode = stat.S_IFREG s.st_size = self.address_space_size return s elif components[0] == "/": s = make_stat(2) s.st_mode = stat.S_IFDIR return s
Example #16
Source File: fuse.py From filesystem_spec with BSD 3-Clause "New" or "Revised" License | 6 votes |
def getattr(self, path, fh=None): path = "".join([self.root, path.lstrip("/")]).rstrip("/") try: info = self.fs.info(path) except FileNotFoundError: raise FuseOSError(ENOENT) data = {"st_uid": 1000, "st_gid": 1000} perm = 0o777 if info["type"] != "file": data["st_mode"] = stat.S_IFDIR | perm data["st_size"] = 0 data["st_blksize"] = 0 else: data["st_mode"] = stat.S_IFREG | perm data["st_size"] = info["size"] data["st_blksize"] = 5 * 2 ** 20 data["st_nlink"] = 1 data["st_atime"] = time.time() data["st_ctime"] = time.time() data["st_mtime"] = time.time() return data
Example #17
Source File: test_smbclient_os.py From smbprotocol with MIT License | 6 votes |
def test_lstat_on_dir(smb_share): dirname = ntpath.join(smb_share, 'dir') smbclient.mkdir(dirname) actual = smbclient.lstat(dirname) assert isinstance(actual, smbclient.SMBStatResult) assert actual.st_atime == actual.st_atime_ns / 1000000000 assert actual.st_mtime == actual.st_mtime_ns / 1000000000 assert actual.st_ctime == actual.st_ctime_ns / 1000000000 assert actual.st_chgtime == actual.st_chgtime_ns / 1000000000 assert actual.st_dev is not None assert actual.st_file_attributes == FileAttributes.FILE_ATTRIBUTE_DIRECTORY assert actual.st_gid == 0 assert actual.st_uid == 0 assert actual.st_ino is not None assert actual.st_mode == stat.S_IFDIR | 0o777 assert actual.st_nlink == 1 assert actual.st_size == 0 assert actual.st_uid == 0 assert actual.st_reparse_tag == 0
Example #18
Source File: dedupfs.py From tgcloud with Apache License 2.0 | 5 votes |
def __insert(self, path, mode, size, rdev=0): # {{{3 parent, name = os.path.split(path) parent_id, parent_ino = self.__path2keys(parent) nlinks = mode & stat.S_IFDIR and 2 or 1 t = self.__newctime() uid, gid = self.__getctx() self.conn.execute( 'INSERT INTO inodes (nlinks, mode, uid, gid, rdev, size, atime, mtime, ctime) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)', (nlinks, mode, uid, gid, rdev, size, t, t, t)) inode = self.__fetchval('SELECT last_insert_rowid()') string_id = self.__intern(name) self.conn.execute('INSERT INTO tree (parent_id, name, inode) VALUES (?, ?, ?)', (parent_id, string_id, inode)) node_id = self.__fetchval('SELECT last_insert_rowid()') self.__cache_set(path, (node_id, inode)) return inode, parent_ino
Example #19
Source File: dedupfs.py From tgcloud with Apache License 2.0 | 5 votes |
def link(self, target_path, link_path, nested=False): # {{{3 # From the link(2) manual page: "If link_path names a directory, link() # shall fail unless the process has appropriate privileges and the # implementation supports using link() on directories." ... :-) # However I've read that FUSE doesn't like multiple directory pathnames # with the same inode number (maybe because of internal caching based on # inode numbers?). try: self.__log_call('link', '%slink(%r -> %r)', nested and ' ' or '', target_path, link_path) if self.read_only: return -errno.EROFS target_ino = self.__path2keys(target_path)[1] link_parent, link_name = os.path.split(link_path) link_parent_id, link_parent_ino = self.__path2keys(link_parent) string_id = self.__intern(link_name) self.conn.execute('INSERT INTO tree (parent_id, name, inode) VALUES (?, ?, ?)', (link_parent_id, string_id, target_ino)) node_id = self.__fetchval('SELECT last_insert_rowid()') self.conn.execute('UPDATE inodes SET nlinks = nlinks + 1 WHERE inode = ?', (target_ino,)) if self.__fetchval('SELECT mode FROM inodes WHERE inode = ?', target_ino) & stat.S_IFDIR: self.conn.execute('UPDATE inodes SET nlinks = nlinks + 1 WHERE inode = ?', (link_parent_ino,)) self.__cache_set(link_path, (node_id, target_ino)) self.__commit_changes(nested) self.__gc_hook(nested) return 0 except Exception, e: self.__rollback_changes(nested) if nested: raise return self.__except_to_status('link', e, errno.EIO)
Example #20
Source File: dedupfs.py From tgcloud with Apache License 2.0 | 5 votes |
def mkdir(self, path, mode): # {{{3 try: self.__log_call('mkdir', 'mkdir(%r, %o)', path, mode) if self.read_only: return -errno.EROFS inode, parent_ino = self.__insert(path, mode | stat.S_IFDIR, 1024 * 4) self.conn.execute('UPDATE inodes SET nlinks = nlinks + 1 WHERE inode = ?', (parent_ino,)) self.__commit_changes() self.__gc_hook() return 0 except Exception, e: self.__rollback_changes() return self.__except_to_status('mkdir', e, errno.EIO)
Example #21
Source File: dptmount.py From dpt-rp1-py with MIT License | 5 votes |
def _get_lstat(self, item): if "reading_date" in item: atime = calendar.timegm( time.strptime(item["reading_date"], "%Y-%m-%dT%H:%M:%SZ") ) else: # access time = now if never read... atime = self.now lstat = dict( st_atime=atime, st_gid=self.gid, st_uid=self.uid, st_ctime=calendar.timegm( time.strptime(item["created_date"], "%Y-%m-%dT%H:%M:%SZ") ), ) # usual thing for directories is st_link keeps number of subdirectories if item["entry_type"] == "folder": lstat["st_nlink"] = 2 # todo: increment nlink in parent dir lstat["st_mode"] = S_IFDIR | 0o755 lstat["st_mtime"] = self.now else: lstat["st_mode"] = S_IFREG | 0o644 lstat["st_mtime"] = calendar.timegm( time.strptime(item["modified_date"], "%Y-%m-%dT%H:%M:%SZ") ) lstat["st_nlink"] = 1 lstat["st_size"] = int(item["file_size"]) #'st_inot': item['entry_id'], 'entry_id': 'fe13e1df-1cfe-4fe3-9e83-3e12e78b8a47', # 'entry_name': '10.1017.pdf', 'entry_path': 'Document/10.1017.pdf', 'entry_type': 'document', # 'file_revision': 'a21ea4b1c368.2.0', # 'is_new': 'false', 'mime_type': 'application/pdf', # 'title': 'untitled', 'total_page': '4'} return lstat
Example #22
Source File: fuse.py From ff4d with BSD 3-Clause "New" or "Revised" License | 5 votes |
def getattr(self, path, fh=None): ''' Returns a dictionary with keys identical to the stat C structure of stat(2). st_atime, st_mtime and st_ctime should be floats. NOTE: There is an incompatibility between Linux and Mac OS X concerning st_nlink of directories. Mac OS X counts all files inside the directory, while Linux counts only the subdirectories. ''' if path != '/': raise FuseOSError(errno.ENOENT) return dict(st_mode=(S_IFDIR | 0o755), st_nlink=2)
Example #23
Source File: file_plugin.py From RSqueak with BSD 3-Clause "New" or "Revised" License | 5 votes |
def primitiveDirectoryLookup(interp, s_frame, w_file_directory, full_path, index): if full_path == '': contents = os.listdir(os.path.sep) else: if not os.path.isdir(full_path): raise PrimitiveFailedError contents = os.listdir(full_path) space = interp.space if index >= len(contents): return space.w_nil # should probably be sorted... contents py_name = contents[index] try: file_path = os.path.join(full_path, py_name) except OSError: raise PrimitiveFailedError try: file_info = os.stat(file_path) except OSError: raise PrimitiveFailedError w_name = space.wrap_string(py_name) w_creationTime = smalltalk_timestamp(space, file_info.st_ctime) w_modificationTime = smalltalk_timestamp(space, file_info.st_mtime) w_dirFlag = space.w_true if stat.S_IFDIR & file_info.st_mode else space.w_false w_fileSize = space.wrap_int(rarithmetic.intmask(file_info.st_size)) return space.wrap_list_unroll_safe([w_name, w_creationTime, w_modificationTime, w_dirFlag, w_fileSize])
Example #24
Source File: scandir.py From pyRevit with GNU General Public License v3.0 | 5 votes |
def is_dir(self, follow_symlinks=True): if (self._d_type == DT_UNKNOWN or (follow_symlinks and self.is_symlink())): try: st = self.stat(follow_symlinks=follow_symlinks) except OSError as e: if e.errno != ENOENT: raise return False return st.st_mode & 0o170000 == S_IFDIR else: return self._d_type == DT_DIR
Example #25
Source File: scandir.py From pyRevit with GNU General Public License v3.0 | 5 votes |
def is_dir(self, follow_symlinks=True): is_symlink = self.is_symlink() if follow_symlinks and is_symlink: try: return self.stat().st_mode & 0o170000 == S_IFDIR except OSError as e: if e.errno != ENOENT: raise return False elif is_symlink: return False else: return (self._find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY != 0)
Example #26
Source File: scandir.py From pyRevit with GNU General Public License v3.0 | 5 votes |
def find_data_to_stat(data): """Convert Win32 FIND_DATA struct to stat_result.""" # First convert Win32 dwFileAttributes to st_mode attributes = data.dwFileAttributes st_mode = 0 if attributes & FILE_ATTRIBUTE_DIRECTORY: st_mode |= S_IFDIR | 0o111 else: st_mode |= S_IFREG if attributes & FILE_ATTRIBUTE_READONLY: st_mode |= 0o444 else: st_mode |= 0o666 if (attributes & FILE_ATTRIBUTE_REPARSE_POINT and data.dwReserved0 == IO_REPARSE_TAG_SYMLINK): st_mode ^= st_mode & 0o170000 st_mode |= S_IFLNK st_size = data.nFileSizeHigh << 32 | data.nFileSizeLow st_atime = filetime_to_time(data.ftLastAccessTime) st_mtime = filetime_to_time(data.ftLastWriteTime) st_ctime = filetime_to_time(data.ftCreationTime) # Some fields set to zero per CPython's posixmodule.c: st_ino, st_dev, # st_nlink, st_uid, st_gid return Win32StatResult(st_mode, 0, 0, 0, 0, 0, st_size, st_atime, st_mtime, st_ctime, int(st_atime * 1000000000), int(st_mtime * 1000000000), int(st_ctime * 1000000000), attributes)
Example #27
Source File: scandir.py From luci-py with Apache License 2.0 | 5 votes |
def is_dir(self, follow_symlinks=True): if (self._d_type == DT_UNKNOWN or (follow_symlinks and self.is_symlink())): try: st = self.stat(follow_symlinks=follow_symlinks) except OSError as e: if e.errno != ENOENT: raise return False return st.st_mode & 0o170000 == S_IFDIR else: return self._d_type == DT_DIR
Example #28
Source File: scandir.py From luci-py with Apache License 2.0 | 5 votes |
def is_dir(self, follow_symlinks=True): is_symlink = self.is_symlink() if follow_symlinks and is_symlink: try: return self.stat().st_mode & 0o170000 == S_IFDIR except OSError as e: if e.errno != ENOENT: raise return False elif is_symlink: return False else: return (self._find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY != 0)
Example #29
Source File: scandir.py From luci-py with Apache License 2.0 | 5 votes |
def find_data_to_stat(data): """Convert Win32 FIND_DATA struct to stat_result.""" # First convert Win32 dwFileAttributes to st_mode attributes = data.dwFileAttributes st_mode = 0 if attributes & FILE_ATTRIBUTE_DIRECTORY: st_mode |= S_IFDIR | 0o111 else: st_mode |= S_IFREG if attributes & FILE_ATTRIBUTE_READONLY: st_mode |= 0o444 else: st_mode |= 0o666 if (attributes & FILE_ATTRIBUTE_REPARSE_POINT and data.dwReserved0 == IO_REPARSE_TAG_SYMLINK): st_mode ^= st_mode & 0o170000 st_mode |= S_IFLNK st_size = data.nFileSizeHigh << 32 | data.nFileSizeLow st_atime = filetime_to_time(data.ftLastAccessTime) st_mtime = filetime_to_time(data.ftLastWriteTime) st_ctime = filetime_to_time(data.ftCreationTime) # Some fields set to zero per CPython's posixmodule.c: st_ino, st_dev, # st_nlink, st_uid, st_gid return Win32StatResult(st_mode, 0, 0, 0, 0, 0, st_size, st_atime, st_mtime, st_ctime, int(st_atime * 1000000000), int(st_mtime * 1000000000), int(st_ctime * 1000000000), attributes)
Example #30
Source File: scandir.py From bazarr with GNU General Public License v3.0 | 5 votes |
def find_data_to_stat(data): """Convert Win32 FIND_DATA struct to stat_result.""" # First convert Win32 dwFileAttributes to st_mode attributes = data.dwFileAttributes st_mode = 0 if attributes & FILE_ATTRIBUTE_DIRECTORY: st_mode |= S_IFDIR | 0o111 else: st_mode |= S_IFREG if attributes & FILE_ATTRIBUTE_READONLY: st_mode |= 0o444 else: st_mode |= 0o666 if (attributes & FILE_ATTRIBUTE_REPARSE_POINT and data.dwReserved0 == IO_REPARSE_TAG_SYMLINK): st_mode ^= st_mode & 0o170000 st_mode |= S_IFLNK st_size = data.nFileSizeHigh << 32 | data.nFileSizeLow st_atime = filetime_to_time(data.ftLastAccessTime) st_mtime = filetime_to_time(data.ftLastWriteTime) st_ctime = filetime_to_time(data.ftCreationTime) # Some fields set to zero per CPython's posixmodule.c: st_ino, st_dev, # st_nlink, st_uid, st_gid return Win32StatResult(st_mode, 0, 0, 0, 0, 0, st_size, st_atime, st_mtime, st_ctime, int(st_atime * 1000000000), int(st_mtime * 1000000000), int(st_ctime * 1000000000), attributes)