Skip to content

Commit

Permalink
Fix #4: broken symlinks delete successfully
Browse files Browse the repository at this point in the history
  • Loading branch information
quackduck committed Jun 18, 2022
1 parent 933d8eb commit b455478
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions rem.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ func main() {
// normal case
ensureTrashDir()
for i, filePath := range os.Args {
if i == 0 { continue }
if i == 0 {
continue
}
if !ignoreArgs[i] {
trashFile(filePath)
}
Expand Down Expand Up @@ -169,8 +171,16 @@ func trashFile(path string) {
return
}
if !exists(path) {
handleErrStr(color.YellowString(path) + " does not exist")
return
fi, err := os.Lstat(path)
if err != nil {
handleErr(err)
return
}
if !(fi.Mode()&os.ModeSymlink == os.ModeSymlink) {
handleErrStr(color.YellowString(path) + " does not exist")
return
}
// the file is a broken symlink which will be deleted to match rm behavior
}
toMoveTo = getTimestampedPath(toMoveTo, exists)
path = getTimestampedPath(path, existsInLog)
Expand Down

0 comments on commit b455478

Please sign in to comment.