Skip to content

Add WithSyncDirectory to optionally fsync the directory after the rename#42

Open
Jille wants to merge 1 commit into
google:masterfrom
Jille:with-sync-directory
Open

Add WithSyncDirectory to optionally fsync the directory after the rename#42
Jille wants to merge 1 commit into
google:masterfrom
Jille:with-sync-directory

Conversation

@Jille

@Jille Jille commented Feb 2, 2024

Copy link
Copy Markdown

WithSyncDirectory configures renameio to fsync the directory after renaming
the file. If that succeeds it's guaranteed the file will be in the new state
even after a crash.

@Jille

Jille commented Feb 2, 2024

Copy link
Copy Markdown
Author

Greetings from quis@ :)

Comment thread tempfile.go
}
t.done = true
if t.syncDirectory {
dh, err := os.OpenFile(filepath.Dir(t.path), os.O_WRONLY, 0)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

On Linux this doesn't work. (Error: open <file>: is a directory)

Simply os.Open(filepath.Dir(t.path)) does work instead.

See also:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is a good point — could you add a test so that the feature is exercised in the CI pipeline?

@stapelberg stapelberg left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Sorry for letting this PR linger for so long. It’s been a busy time recently.

The reason why the renameio package currently doesn’t provide this feature is so that the user has more control over when a sync happens (as applications often write many files), but I don’t mind adding this for use-cases where only a single file needs to be written reliably.

Comment thread tempfile.go
}
t.done = true
if t.syncDirectory {
dh, err := os.OpenFile(filepath.Dir(t.path), os.O_WRONLY, 0)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is a good point — could you add a test so that the feature is exercised in the CI pipeline?

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.

3 participants