From b482cbda585848c0d5f5345711fe338e319c0adf Mon Sep 17 00:00:00 2001 From: Anish Athalye Date: Thu, 17 Nov 2016 14:12:22 -0500 Subject: [PATCH] Make force only delete files when target exists --- plugins/link.py | 3 ++- .../link-force-leaves-when-nonexistent.bash | 24 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 test/tests/link-force-leaves-when-nonexistent.bash 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 <