aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Jon Bernard <jbernard@jbernard.io> 2018-04-17 11:02:35 -0400
committerGravatar Jon Bernard <jbernard@jbernard.io> 2018-04-17 11:02:35 -0400
commit18a90a011fefb31bb40ec8da4b863910376e648f (patch)
tree9822b220ebd54aca8b6d94df70588fec8f4fdcaf
parentae6723be0c94e1e979523efbffa39cd0f422db41 (diff)
downloaddotfiles-18a90a011fefb31bb40ec8da4b863910376e648f.tar.gz
dotfiles-18a90a011fefb31bb40ec8da4b863910376e648f.tar.bz2
dotfiles-18a90a011fefb31bb40ec8da4b863910376e648f.zip
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.
-rw-r--r--dotfiles/dotfile.py14
1 files 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):