Skip to content

Commit

Permalink
Handle ENOENT when autocleaning
Browse files Browse the repository at this point in the history
If the file doesn't exist, the autoclean was unnecessary, but it was
still "successful".
  • Loading branch information
CGamesPlay committed Sep 15, 2020
1 parent dd2c208 commit 4ee4cdf
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
6 changes: 3 additions & 3 deletions Dfm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand All @@ -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)
}
}
Expand Down
18 changes: 18 additions & 0 deletions testdata/TestDfm/missing-link.sh
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions testdata/TestDfm/missing-link.sh.snap
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 4ee4cdf

Please sign in to comment.