OP-4504 - safer comparison of two paths

This commit is contained in:
Petr Kalis 2022-12-15 16:28:49 +01:00
parent ee58c0ce48
commit da274a7c8d

View file

@ -92,7 +92,9 @@ class FileTransaction(object):
def process(self):
# Backup any existing files
for dst, (src, _) in self._transfers.items():
if dst == src or not os.path.exists(dst):
self.log.debug("Checking file ... {} -> {}".format(src, dst))
path_same = self._same_paths(src, dst)
if path_same or not os.path.exists(dst):
continue
# Backup original file
@ -105,7 +107,8 @@ class FileTransaction(object):
# Copy the files to transfer
for dst, (src, opts) in self._transfers.items():
if dst == src:
path_same = self._same_paths(src, dst)
if path_same:
self.log.debug(
"Source and destionation are same files {} -> {}".format(
src, dst))
@ -182,3 +185,10 @@ class FileTransaction(object):
else:
self.log.critical("An unexpected error occurred.")
six.reraise(*sys.exc_info())
def _same_paths(self, src, dst):
# handles same paths but with C:/project vs c:/project
if os.path.exists(src) and os.path.exists(dst):
return os.path.samefile(src, dst)
return False