Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/20260529095325.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
:bug: Ensure that there is an explicit check that a path is not a directory before unlinking
15 changes: 11 additions & 4 deletions utils/filesystem/extendedosfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,21 @@ type ExtendedOsFs struct {
}

func (c *ExtendedOsFs) Remove(name string) (err error) {
// The following is to ensure sockets are correctly removed
// https://stackoverflow.com/questions/16681944/how-to-reliably-unlink-a-unix-domain-socket-in-go-programming-language
err = commonerrors.Ignore(ConvertFileSystemError(syscall.Unlink(name)), commonerrors.ErrNotFound)
err = commonerrors.IgnoreCorrespondTo(err, "is a directory")
info, err := c.Stat(name)
if err != nil {
err = ConvertFileSystemError(err)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if error is notFound the error should be ignored

return
}

if !info.IsDir() {
// The following is to ensure sockets are correctly removed (must be unlinked/closed before reuse)
// https://stackoverflow.com/questions/16681944/how-to-reliably-unlink-a-unix-domain-socket-in-go-programming-language
err = commonerrors.Ignore(ConvertFileSystemError(syscall.Unlink(name)), commonerrors.ErrNotFound)
if err != nil {
return
}
}

err = commonerrors.Ignore(ConvertFileSystemError(c.OsFs.Remove(name)), commonerrors.ErrNotFound)
return
}
Expand Down
Loading