Skip to content

Commit 3977d43

Browse files
🐛 Ensure that there is an explicit check that a path is not a directory before unlinking
1 parent 18b53be commit 3977d43

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

changes/20260529095325.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
:bug: Ensure that there is an explicit check that a path is not a directory before unlinking

utils/filesystem/extendedosfs.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,21 @@ type ExtendedOsFs struct {
2222
}
2323

2424
func (c *ExtendedOsFs) Remove(name string) (err error) {
25-
// The following is to ensure sockets are correctly removed
26-
// https://stackoverflow.com/questions/16681944/how-to-reliably-unlink-a-unix-domain-socket-in-go-programming-language
27-
err = commonerrors.Ignore(ConvertFileSystemError(syscall.Unlink(name)), commonerrors.ErrNotFound)
28-
err = commonerrors.IgnoreCorrespondTo(err, "is a directory")
25+
info, err := c.OsFs.Stat(name)
2926
if err != nil {
27+
err = ConvertFileSystemError(err)
3028
return
3129
}
3230

31+
if !info.IsDir() {
32+
// The following is to ensure sockets are correctly removed
33+
// https://stackoverflow.com/questions/16681944/how-to-reliably-unlink-a-unix-domain-socket-in-go-programming-language
34+
err = commonerrors.Ignore(ConvertFileSystemError(syscall.Unlink(name)), commonerrors.ErrNotFound)
35+
if err != nil {
36+
return
37+
}
38+
}
39+
3340
err = commonerrors.Ignore(ConvertFileSystemError(c.OsFs.Remove(name)), commonerrors.ErrNotFound)
3441
return
3542
}

0 commit comments

Comments
 (0)