1
0
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:
deadc0de6
2018-06-08 22:33:11 +02:00
parent 6c6304e339
commit 1b3ce007bc
2 changed files with 12 additions and 0 deletions

View File

@@ -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)))

View File

@@ -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))