1
0
mirror of https://github.com/deadc0de6/dotdrop.git synced 2026-02-05 04:29:47 +00:00

fix bug for #179

This commit is contained in:
deadc0de6
2019-07-23 06:08:13 +02:00
parent 709cde144f
commit d5e8b1d294
2 changed files with 14 additions and 11 deletions

View File

@@ -31,6 +31,14 @@ class Comparator:
if self.debug:
self.log.dbg('comparing {} and {}'.format(left, right))
self.log.dbg('ignore pattern(s): {}'.format(ignore))
# test type of file
if os.path.isdir(left) and not os.path.isdir(right):
return '\"{}\" is a dir while \"{}\" is a file\n'.format(left,
right)
if not os.path.isdir(left) and os.path.isdir(right):
return '\"{}\" is a file while \"{}\" is a dir\n'.format(left,
right)
# test content
if not os.path.isdir(left):
if self.debug:
self.log.dbg('is file')

View File

@@ -219,9 +219,7 @@ class Installer:
self.log.dry('would remove {} and link to {}'.format(dst, src))
return True, None
if self.showdiff:
with open(src, 'rb') as f:
content = f.read()
self._diff_before_write(src, dst, content)
self._diff_before_write(src, dst)
msg = 'Remove "{}" for link creation?'.format(dst)
if self.safe and not self.log.ask(msg):
err = 'ignoring "{}", link was not created'.format(dst)
@@ -375,7 +373,7 @@ class Installer:
if self.debug:
self.log.dbg('change detected for {}'.format(dst))
if self.showdiff:
self._diff_before_write(src, dst, content)
self._diff_before_write(src, dst)
if not self.log.ask('Overwrite \"{}\"'.format(dst)):
self.log.warn('ignoring {}'.format(dst))
return 1, None
@@ -406,19 +404,16 @@ class Installer:
os.chmod(dst, rights)
return 0, None
def _diff_before_write(self, src, dst, src_content):
def _diff_before_write(self, src, dst):
"""diff before writing when using --showdiff - not efficient"""
# create tmp to diff for templates
tmpfile = utils.get_tmpfile()
with open(tmpfile, 'wb') as f:
f.write(src_content)
comp = Comparator(debug=self.debug)
diff = comp.compare(tmpfile, dst)
diff = comp.compare(src, dst)
# fake the output for readability
if not diff:
return
self.log.log('diff \"{}\" VS \"{}\"'.format(src, dst))
self.log.emph(diff)
if tmpfile:
utils.remove(tmpfile)
def _create_dirs(self, directory):
"""mkdir -p <directory>"""