Fix macOS fsync error when saving SMB shared file #4016
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Correctly handle fcntl() failure when calling on unsupported storage systems (e.g. SMB network shared file). The current code only checks for ENOTTY but the OS actually returns ENOTSUP (45) when trying to save to a network shared file. Currently this incorrect handling leads to files not being properly fsync'ed and display a scary error to the user.
Reproduce
To reproduce this case, on a Mac, just mount a shared SMB drive (from Windows). Then try to open a shared network file and save to it. You see see an error saying "E667: Fsync failed".
Notes
Annoyingly, both
ENOTTY
andENOTSUP
error codes are not documented in the Applefcntl
man page.Descriptions for
ENOTSUP
can be found here:This makes sense to me because the docs says
fcntl
is only implemented for some filesystems so returningENOTSUP
just means you should usefsync
as a backup.An alternative is to simply not check error code and always try
fsync
as a backup.Related