mirror of
https://github.com/arsenetar/dupeguru.git
synced 2025-03-10 05:34:36 +00:00
Update fs.py to optimize stat() calls
- Update to get size and mtime at time of class creation when os.DirEntry is used for initialization. - Folders still calculate size later for folder scans. - Ref #962, #959
This commit is contained in:
parent
a37b5b0eeb
commit
a470a8de25
14
core/fs.py
14
core/fs.py
@ -187,9 +187,14 @@ class File:
|
|||||||
__slots__ = ("path", "is_ref", "words") + tuple(INITIAL_INFO.keys())
|
__slots__ = ("path", "is_ref", "words") + tuple(INITIAL_INFO.keys())
|
||||||
|
|
||||||
def __init__(self, path):
|
def __init__(self, path):
|
||||||
self.path = path
|
|
||||||
for attrname in self.INITIAL_INFO:
|
for attrname in self.INITIAL_INFO:
|
||||||
setattr(self, attrname, NOT_SET)
|
setattr(self, attrname, NOT_SET)
|
||||||
|
if type(path) is os.DirEntry:
|
||||||
|
self.path = Path(path.path)
|
||||||
|
self.size = nonone(path.stat().st_size, 0)
|
||||||
|
self.mtime = nonone(path.stat().st_mtime, 0)
|
||||||
|
else:
|
||||||
|
self.path = path
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<{} {}>".format(self.__class__.__name__, str(self.path))
|
return "<{} {}>".format(self.__class__.__name__, str(self.path))
|
||||||
@ -346,6 +351,7 @@ class Folder(File):
|
|||||||
|
|
||||||
def __init__(self, path):
|
def __init__(self, path):
|
||||||
File.__init__(self, path)
|
File.__init__(self, path)
|
||||||
|
self.size = NOT_SET
|
||||||
self._subfolders = None
|
self._subfolders = None
|
||||||
|
|
||||||
def _all_items(self):
|
def _all_items(self):
|
||||||
@ -378,8 +384,8 @@ class Folder(File):
|
|||||||
def subfolders(self):
|
def subfolders(self):
|
||||||
if self._subfolders is None:
|
if self._subfolders is None:
|
||||||
with os.scandir(self.path) as iter:
|
with os.scandir(self.path) as iter:
|
||||||
subfolders = [p.path for p in iter if not p.is_symlink() and p.is_dir()]
|
subfolders = [p for p in iter if not p.is_symlink() and p.is_dir()]
|
||||||
self._subfolders = [self.__class__(Path(p)) for p in subfolders]
|
self._subfolders = [self.__class__(p) for p in subfolders]
|
||||||
return self._subfolders
|
return self._subfolders
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@ -397,8 +403,6 @@ def get_file(path, fileclasses=[File]):
|
|||||||
"""
|
"""
|
||||||
for fileclass in fileclasses:
|
for fileclass in fileclasses:
|
||||||
if fileclass.can_handle(path):
|
if fileclass.can_handle(path):
|
||||||
if type(path) is os.DirEntry:
|
|
||||||
return fileclass(Path(path.path))
|
|
||||||
return fileclass(path)
|
return fileclass(path)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user