Skip to content

Conversation

tharvik
Copy link

@tharvik tharvik commented Apr 2, 2019

Allows to flock a directory by retrying without os.O_CREATE if the syscall returns syscall.EISDIR.
There is now two instance of the same test suite, one creating a temporary file, the other, a temporary directory.
btw, reopenFDOnError also use os.OpenFile, but I was unable to trigger this path via the tests. From Linux, I don't think that the hack is needed anymore (hopefully, otherwise, flock can't be use on directory via NFS as unable to open it with os.O_RDWR).
btw, Windows is not supported, I was unable to find a locking function for directories (and also, unable to test it).

flock.go Outdated
return err
// retry for directory
errno := err.(*os.PathError).Err.(syscall.Errno)
if errno == syscall.EISDIR {
Copy link
Member

Choose a reason for hiding this comment

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

I'm a little worried that if we add another platform, like the in-development AIX code, this will break. Is this constant available on all platforms that Go supports out of the box?

Copy link
Member

@theckman theckman left a comment

Choose a reason for hiding this comment

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

I think to support this, at a minimum, we would need to move the OpenFile error handling code into the platform-specific flock.go files. To quote the proverbs:

Syscall must always be guarded with build tags.

@tharvik tharvik closed this Oct 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants