From 18a90a011fefb31bb40ec8da4b863910376e648f Mon Sep 17 00:00:00 2001 From: Jon Bernard Date: Tue, 17 Apr 2018 11:02:35 -0400 Subject: Begin adding support for file copy Until now, dotfiles has only linked files using symbolic links. This doesn't always work, some configuration files cannot be symlinks. This commit begins adding support for file copy instead of linking. File status is still maintained, if the dotfile is copied and the content differ from what's in the repository, a conflict is displayed. Otherwise the file is an exact duplicate and that's what we want. Still to do is exposing a command to copy from the cli and adding support to remove() to do the right thing. It may also be nice to see file status (symlink vs. copy) in status output, still undecided. --- dotfiles/dotfile.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/dotfiles/dotfile.py b/dotfiles/dotfile.py index 8c5b38e..d59f07b 100644 --- a/dotfiles/dotfile.py +++ b/dotfiles/dotfile.py @@ -34,6 +34,7 @@ class Dotfile(object): echo('MKDIR %s' % dir) else: dir.ensure_dir() + ensure(py.path.local(self.name.dirname), debug) ensure(py.path.local(self.target.dirname), debug) @@ -71,11 +72,16 @@ class Dotfile(object): # only for testing, cli should never reach this state return 'error' elif self.name.check(exists=0): - # no $HOME symlink + # no $HOME file or symlink return 'missing' - elif self.name.check(link=0) or not self.name.samefile(self.target): - # if name exists but isn't a link to the target - return 'conflict' + elif self.name.islink(): + # name exists, is a link, but isn't a link to the target + if not self.name.samefile(self.target): + return 'conflict' + else: + # name exists, is a file, but differs from the target + if self.name.computehash() != self.target.computehash(): + return 'conflict' return 'ok' def add(self, debug=False): -- cgit v1.2.3