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.Statfollows 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, theFileInforeturned byos.Lstatdescribes that symlink, andos.Lstatmakes no attempt to follow it
Please inspect the following screenshots for visual details
Replaces
os.Stat
withos.Lstat
to resolve the issue with a symlink removal, which emerges when a symlink is targeted to a directoryThe thing is
os.Stat
follows symlinks by default thus returnedFileInfo
describes the target file system entity (directory
) instead of a symlink itselfThis 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 statementsrm: <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, theFileInfo
returned byos.Lstat
describes that symlink, andos.Lstat
makes no attempt to follow itPlease inspect the following screenshots for visual details