[path] improve 'exists()' performance
call 'os.stat()' directly
This commit is contained in:
@@ -160,8 +160,12 @@ class PathFormat():
|
|||||||
|
|
||||||
def exists(self):
|
def exists(self):
|
||||||
"""Return True if the file exists on disk"""
|
"""Return True if the file exists on disk"""
|
||||||
if self.extension and os.path.exists(self.realpath):
|
if self.extension:
|
||||||
return self.check_file()
|
try:
|
||||||
|
os.stat(self.realpath) # raises OSError if file doesn't exist
|
||||||
|
return self.check_file()
|
||||||
|
except OSError:
|
||||||
|
pass
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def check_file(self):
|
def check_file(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user