diff options
author | Anish Athalye <me@anishathalye.com> | 2016-11-17 14:12:22 -0500 |
---|---|---|
committer | Anish Athalye <me@anishathalye.com> | 2016-11-17 14:12:22 -0500 |
commit | b482cbda585848c0d5f5345711fe338e319c0adf (patch) | |
tree | 33e32ac2d88a869461ae07b8bda5376cd0827433 | |
parent | 913d5484ca49a9860b160ac2e80258cc7a15c381 (diff) |
Make force only delete files when target exists
-rw-r--r-- | plugins/link.py | 3 | ||||
-rw-r--r-- | test/tests/link-force-leaves-when-nonexistent.bash | 24 |
2 files changed, 26 insertions, 1 deletions
diff --git a/plugins/link.py b/plugins/link.py index 483d35e..ff8685e 100644 --- a/plugins/link.py +++ b/plugins/link.py @@ -37,7 +37,8 @@ class Link(dotbot.Plugin): if create: success &= self._create(destination) if force or relink: - success &= self._delete(path, destination, relative, force) + if self._exists(path): + success &= self._delete(path, destination, relative, force) success &= self._link(path, destination, relative) if success: self._log.info('All links have been set up') diff --git a/test/tests/link-force-leaves-when-nonexistent.bash b/test/tests/link-force-leaves-when-nonexistent.bash new file mode 100644 index 0000000..fe6e33c --- /dev/null +++ b/test/tests/link-force-leaves-when-nonexistent.bash @@ -0,0 +1,24 @@ +test_description='force leaves file when target nonexistent' +. '../test-lib.bash' + +test_expect_success 'setup' ' +mkdir ~/dir && +touch ~/file +' + +test_expect_failure 'run' ' +run_dotbot <<EOF +- link: + ~/dir: + path: dir + force: true + ~/file: + path: file + force: true +EOF +' + +test_expect_success 'test' ' +test -d ~/dir && +test -f ~/file +' |