WestleyR / srm

Safe remove ('rm') command with caching and undo/recover
BSD 3-Clause Clear License
8 stars 2 forks source link

Resolves the issue with a symlink removal #4

Closed juliyvchirkov closed 1 year ago

juliyvchirkov commented 1 year ago

Replaces os.Stat with os.Lstat to resolve the issue with a symlink removal, which emerges when a symlink is targeted to a directory

The thing is os.Stat follows symlinks by default thus returned FileInfo describes the target file system entity (directory) instead of a symlink itself

This makes removal of a symlink targeted to a directory completely not possible 'cause the command srm <a symlink targeted to a directory> fails with the statement srm: <a symlink targeted to a directory>: is a directory

os.Lstat delivers exactly the same FileInfo data structure for a file system entity and implements the same subroutines as os.Stat does except for symlink processing. If the file system entity is a symlink, the FileInfo returned by os.Lstat describes that symlink, and os.Lstat makes no attempt to follow it

Please inspect the following screenshots for visual details

1 2 3