mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-11 05:34:17 +00:00
properly check if same file
This commit is contained in:
@@ -214,7 +214,7 @@ def update(opts, conf, path):
|
|||||||
src_clean = src
|
src_clean = src
|
||||||
if os.path.isdir(src):
|
if os.path.isdir(src):
|
||||||
src_clean = os.path.join(src, '..')
|
src_clean = os.path.join(src, '..')
|
||||||
if os.path.samefile(src_clean, path):
|
if samefile(src_clean, path):
|
||||||
# symlink loop
|
# symlink loop
|
||||||
Log.err('dotfile points to itself: {}'.format(path))
|
Log.err('dotfile points to itself: {}'.format(path))
|
||||||
return False
|
return False
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ class Installer:
|
|||||||
"""install the src to dst using a template"""
|
"""install the src to dst using a template"""
|
||||||
src = os.path.join(self.base, os.path.expanduser(src))
|
src = os.path.join(self.base, os.path.expanduser(src))
|
||||||
dst = os.path.join(self.base, os.path.expanduser(dst))
|
dst = os.path.join(self.base, os.path.expanduser(dst))
|
||||||
if os.path.samefile(src, dst):
|
if utils.samefile(src, dst):
|
||||||
# symlink loop
|
# symlink loop
|
||||||
self.log.err('dotfile points to itself: {}'.format(dst))
|
self.log.err('dotfile points to itself: {}'.format(dst))
|
||||||
return []
|
return []
|
||||||
@@ -76,7 +76,7 @@ class Installer:
|
|||||||
def _handle_file(self, templater, profile, src, dst):
|
def _handle_file(self, templater, profile, src, dst):
|
||||||
"""install src to dst when is a file"""
|
"""install src to dst when is a file"""
|
||||||
self.log.dbg('generate template for {}'.format(src))
|
self.log.dbg('generate template for {}'.format(src))
|
||||||
if os.path.samefile(src, dst):
|
if utils.samefile(src, dst):
|
||||||
# symlink loop
|
# symlink loop
|
||||||
self.log.err('dotfile points to itself: {}'.format(dst))
|
self.log.err('dotfile points to itself: {}'.format(dst))
|
||||||
return []
|
return []
|
||||||
|
|||||||
@@ -52,3 +52,12 @@ def remove(path):
|
|||||||
rmtree(path)
|
rmtree(path)
|
||||||
else:
|
else:
|
||||||
raise OSError("Unsupported file type for deletion: {}".format(path))
|
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)
|
||||||
|
|||||||
Reference in New Issue
Block a user