mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-05 03:19:43 +00:00
fix symlink loop for #45
This commit is contained in:
@@ -214,6 +214,10 @@ 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):
|
||||
# symlink loop
|
||||
Log.err('dotfile points to itself: {}'.format(path))
|
||||
return False
|
||||
cmd = ['cp', '-R', '-L', os.path.expanduser(path), src_clean]
|
||||
if opts['dry']:
|
||||
LOG.dry('would run: {}'.format(' '.join(cmd)))
|
||||
|
||||
@@ -32,6 +32,10 @@ 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):
|
||||
# symlink loop
|
||||
self.log.err('dotfile points to itself: {}'.format(dst))
|
||||
return []
|
||||
self.log.dbg('install {} to {}'.format(src, dst))
|
||||
if os.path.isdir(src):
|
||||
return self._handle_dir(templater, profile, src, dst)
|
||||
@@ -72,6 +76,10 @@ 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):
|
||||
# symlink loop
|
||||
self.log.err('dotfile points to itself: {}'.format(dst))
|
||||
return []
|
||||
content = templater.generate(src, profile)
|
||||
if content is None:
|
||||
self.log.err('generate from template \"{}\"'.format(src))
|
||||
|
||||
Reference in New Issue
Block a user