From 1b3ce007bc3ec1af7a31de83ea1320df6ae7106b Mon Sep 17 00:00:00 2001 From: deadc0de6 Date: Fri, 8 Jun 2018 22:33:11 +0200 Subject: [PATCH] fix symlink loop for #45 --- dotdrop/dotdrop.py | 4 ++++ dotdrop/installer.py | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/dotdrop/dotdrop.py b/dotdrop/dotdrop.py index 81441a5..6395807 100644 --- a/dotdrop/dotdrop.py +++ b/dotdrop/dotdrop.py @@ -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))) diff --git a/dotdrop/installer.py b/dotdrop/installer.py index ee4acd1..d8fb7b2 100644 --- a/dotdrop/installer.py +++ b/dotdrop/installer.py @@ -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))