diff --git a/Dfm.go b/Dfm.go index b987234..ac659bc 100644 --- a/Dfm.go +++ b/Dfm.go @@ -461,8 +461,8 @@ func (dfm *Dfm) EjectFiles(inputFilenames []string, errorHandler ErrorHandler) e func (dfm *Dfm) autoclean(nextManifest map[string]bool) { var toRemove []string for filename := range dfm.Config.manifest { - _, found := nextManifest[filename] - if !found { + _, needed := nextManifest[filename] + if !needed { toRemove = append(toRemove, filename) } } @@ -476,7 +476,7 @@ func (dfm *Dfm) autoclean(nextManifest map[string]bool) { } } dfm.log(OperationRemove, filename, "", err) - if err == nil { + if err == nil || os.IsNotExist(err) { delete(dfm.Config.manifest, filename) } } diff --git a/testdata/TestDfm/missing-link.sh b/testdata/TestDfm/missing-link.sh new file mode 100644 index 0000000..9373aaf --- /dev/null +++ b/testdata/TestDfm/missing-link.sh @@ -0,0 +1,18 @@ +#!/bin/bash +# Tests dfm correctly handling a file that has been unlinked behind dfm's back. +set -e +. "$(dirname "$0")/../helpers.sh" + +export HOME="$(pwd)/home" +export DFM_DIR="$HOME/dfmdir" + +mkdir -p ~/dfmdir/files +echo 'config' > ~/dfmdir/files/.bashrc + +dfm init --repos files +dfm link + +rm ~/.bashrc +rm ~/dfmdir/files/.bashrc +dfm link +dfm link # no output on second run diff --git a/testdata/TestDfm/missing-link.sh.snap b/testdata/TestDfm/missing-link.sh.snap new file mode 100644 index 0000000..0818cf8 --- /dev/null +++ b/testdata/TestDfm/missing-link.sh.snap @@ -0,0 +1,7 @@ +$ dfm init --repos files +Initialized /test/home/dfmdir as a dfm directory. +$ dfm link +files/.bashrc -> /test/home/.bashrc +$ dfm link +removed .bashrc +$ dfm link