Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkg/ioutils: move atomic file-writers to a separate (pkg/atomicwriter) package #49171

Merged
merged 1 commit into from
Jan 8, 2025

Conversation

thaJeztah
Copy link
Member

@thaJeztah thaJeztah commented Dec 28, 2024

- What I did

- How I did it

- How to verify it

- Description for the changelog

Go-SDK: pkg/ioutils: deprecate `NewAtomicFileWriter` in favor of `pkg/atomicwriter.New`.
Go-SDK: pkg/ioutils: deprecate `AtomicWriteFile` in favor of `pkg/atomicwriter.WriteFile`.
Go-SDK: pkg/ioutils: deprecate `AtomicWriteSet` in favor of `pkg/atomicwriter.WriteSet`.
Go-SDK: pkg/ioutils: deprecate `NewAtomicWriteSet` in favor of `pkg/atomicwriter.NewWriteSet`.

- A picture of a cute animal (not mandatory but encouraged)

@thaJeztah thaJeztah added status/2-code-review impact/deprecation kind/refactor PR's that refactor, or clean-up code area/go-sdk Changes affecting the Go SDK impact/go-sdk Noteworthy (compatibility changes) in the Go SDK labels Dec 28, 2024
@thaJeztah thaJeztah added this to the 28.0.0 milestone Dec 28, 2024
@thaJeztah thaJeztah self-assigned this Dec 28, 2024
@thaJeztah thaJeztah requested a review from cpuguy83 as a code owner December 28, 2024 16:10
@thaJeztah thaJeztah mentioned this pull request Dec 28, 2024
74 tasks
@thaJeztah thaJeztah force-pushed the move_atomicwriters branch 2 times, most recently from 154c285 to 9c2ae86 Compare January 1, 2025 15:14
Comment on lines 16 to 26
func NewAtomicFileWriter(filename string, perm os.FileMode) (io.WriteCloser, error) {
return fswriter.NewAtomicFileWriter(filename, perm)
}

// AtomicWriteFile atomically writes data to a file named by filename and with the specified permission bits.
// NOTE: umask is not considered for the file's permissions.
//
// Deprecated: use [fswriter.AtomicWriteFile] instead.
func AtomicWriteFile(filename string, data []byte, perm os.FileMode) error {
return fswriter.AtomicWriteFile(filename, data, perm)
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Could use some feedback / thoughts on this;

I was originally (some time ago) considering to move these to a atomic package, for a slightly nicer interface;

  • atomic.NewFileWriter or even atomic.NewWriter
  • atomic.WriteFile
  • atomic.NewWriteSet

But I wasn't sure if that would be too easily confused / conflict with Go's atomic packages.

FWIW; there's some existing projects handling atomic write operations as well that we could even consider adopting;

Copy link
Member Author

Choose a reason for hiding this comment

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

Pushed a temporary second commit to use atomicwriter as name for this instead of fswriter - will squash if we think this looks good 👍

Copy link
Contributor

Choose a reason for hiding this comment

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

atomic might indeed be confusing with the Go's atomic.

Other possible name I thought of was atomicfile, since this package mostly deals with files. Then WriteFile would become just Write and New would become NewWriter (it has less usages than WriteFile, so I don't feel bad about making it a bit longer 😄).

Copy link
Contributor

Choose a reason for hiding this comment

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

atomicwriter SGTM though

Copy link
Member Author

Choose a reason for hiding this comment

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

Naming is hard!

I tried to keep WriteFile as a parallel to os.WriteFile as it's effectively a drop-in replacement, so I thought it would be nice to keep that name the same.

Copy link
Member

Choose a reason for hiding this comment

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

atomicwriter sounds good to me! Seems like it's the best option to both:

  • avoid confusion with atomic/my LSP importing the wrong package and
  • keeping WriteFile for the os parallel`

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks!

@thaJeztah thaJeztah force-pushed the move_atomicwriters branch 2 times, most recently from eb135d3 to d774014 Compare January 6, 2025 20:17
@thaJeztah thaJeztah changed the title pkg/ioutils: move atomic file-writers to a separate (pkg/fswriter) package pkg/ioutils: move atomic file-writers to a separate (pkg/atomicwriter) package Jan 6, 2025
…) package

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Copy link
Member

@laurazard laurazard left a comment

Choose a reason for hiding this comment

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

LGTM

@thaJeztah
Copy link
Member Author

I'll bring this one in, and update my CLI vendor to update uses of the old location 👍

@thaJeztah thaJeztah merged commit d127f16 into moby:master Jan 8, 2025
140 checks passed
@thaJeztah thaJeztah deleted the move_atomicwriters branch January 8, 2025 16:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/go-sdk Changes affecting the Go SDK impact/deprecation impact/go-sdk Noteworthy (compatibility changes) in the Go SDK kind/refactor PR's that refactor, or clean-up code status/2-code-review
Projects
Development

Successfully merging this pull request may close these issues.

3 participants