diff --git a/dotdrop/dotdrop.py b/dotdrop/dotdrop.py index 6395807..9b7ad36 100644 --- a/dotdrop/dotdrop.py +++ b/dotdrop/dotdrop.py @@ -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 diff --git a/dotdrop/installer.py b/dotdrop/installer.py index d8fb7b2..1fe3f42 100644 --- a/dotdrop/installer.py +++ b/dotdrop/installer.py @@ -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 [] diff --git a/dotdrop/utils.py b/dotdrop/utils.py index b862f0b..54f6415 100644 --- a/dotdrop/utils.py +++ b/dotdrop/utils.py @@ -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)