google / google/renameio

Add tips on preserving file metadata

Open
#19 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
679
Forks
34
PR merge metrics
No merged PRs in 30d

Description

I have a program that used to overwrite input files in-place, and that was lacking atomicity. When switching to renameio, the biggest question for me was - what `perm` bits should I use? The old `os.OpenFile(path, os.O_WRONLY|os.O_TRUNC, 0)` call didn't need to change any permissions, so it's not obvious what should I do here.

I don't think there's a way to replace a file and keep its permission bits in an atomic way. For now, I'm just using `os.Lstat` first to grab the bits, then using them for `renameio.WriteFile`. I realise that's racy, for example if the permissions change between the two operations, but it seems like an OK tradeoff while keeping it impossible to lose data.

Maybe I'm alone in seeing this as a gap in the README or docs. Do you reckon any tips would be a good addition?

Contributor guide

Open the contributing guide

Research direction

Read the README or existing docs for renameio.WriteFile and compare them with the issue's os.Lstat and perm-bit example. Add guidance explaining how to choose permissions when replacing files and document the metadata-preservation and race considerations described in the issue; done means a user can understand the recommended approach.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.