1
0
mirror of https://github.com/deadc0de6/dotdrop.git synced 2026-02-05 07:58:48 +00:00

properly check if same file

This commit is contained in:
deadc0de6
2018-06-08 22:40:39 +02:00
parent 1b3ce007bc
commit 952230ef47
3 changed files with 12 additions and 3 deletions

View File

@@ -214,7 +214,7 @@ def update(opts, conf, path):
src_clean = src
if os.path.isdir(src):
src_clean = os.path.join(src, '..')
if os.path.samefile(src_clean, path):
if samefile(src_clean, path):
# symlink loop
Log.err('dotfile points to itself: {}'.format(path))
return False

View File

@@ -32,7 +32,7 @@ class Installer:
"""install the src to dst using a template"""
src = os.path.join(self.base, os.path.expanduser(src))
dst = os.path.join(self.base, os.path.expanduser(dst))
if os.path.samefile(src, dst):
if utils.samefile(src, dst):
# symlink loop
self.log.err('dotfile points to itself: {}'.format(dst))
return []
@@ -76,7 +76,7 @@ class Installer:
def _handle_file(self, templater, profile, src, dst):
"""install src to dst when is a file"""
self.log.dbg('generate template for {}'.format(src))
if os.path.samefile(src, dst):
if utils.samefile(src, dst):
# symlink loop
self.log.err('dotfile points to itself: {}'.format(dst))
return []

View File

@@ -52,3 +52,12 @@ def remove(path):
rmtree(path)
else:
raise OSError("Unsupported file type for deletion: {}".format(path))
def samefile(path1, path2):
"""return True if represent the same file"""
if not os.path.exists(path1):
return False
if not os.path.exists(path2):
return False
return os.path.samefile(path1, path2)