Skip to content
Merged
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/202605290935.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed filesystem removal on macOS when deleting directories using unlink.
14 changes: 10 additions & 4 deletions utils/filesystem/extendedosfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,19 @@ 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")
if err != nil {
unlinkErr := commonerrors.Ignore(ConvertFileSystemError(syscall.Unlink(name)), commonerrors.ErrNotFound)
unlinkErr = commonerrors.IgnoreCorrespondTo(unlinkErr, "is a directory")

removeErr := commonerrors.Ignore(ConvertFileSystemError(c.OsFs.Remove(name)), commonerrors.ErrNotFound)

if unlinkErr != nil && removeErr != nil {
// There is a behavioural difference on Mac vs Linux where performing an Unlink on a directory causes a EPERM which
// falsely gives the impression of a permissions issue, but directly using Remove works. So rather than fail on the
// first error this will only return an error if neither strategy works.
err = commonerrors.Join(unlinkErr, removeErr)
return
}
Comment thread
phawxby marked this conversation as resolved.

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

Expand Down
Loading