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

Supporting mode='x' with conditional requests to prevent overwriting #919

Closed
gtebbutt opened this issue Dec 2, 2024 · 3 comments
Closed

Comments

@gtebbutt
Copy link

gtebbutt commented Dec 2, 2024

I'm a new user of this library, so apologies in advance if I've missed something obvious!

I was hoping to use it as a drop-in replacement for the native open() function, but my existing code uses mode='x' to prevent accidental overwriting in case of a filename collision. I couldn't see any indication that's supported here, but I did find that S3 has recently added support for conditional requests, and Cloudflare R2 (which I'm using right now) supports the same headers, so it looks like it'd now be possible to add in a way that's not subject to race conditions.

Is this something that's planned or would be of interest? Seems like it'd be a useful addition that fits nicely within the scope of matching the existing python filesystem API.

@gtebbutt
Copy link
Author

gtebbutt commented Dec 2, 2024

Ah, I've just realised there's an open PR (#917) from a few days ago implementing exactly this! Problem solved, by the look of it!

@gtebbutt gtebbutt closed this as completed Dec 2, 2024
@martindurant
Copy link
Member

Specifically: it will work locally, but the s3 PR is not yet done, because the mocker library doesn't implement it :|. I believe it does work, and I intend to implement it for GCS amd azure and maybe others. None of this is released.

@gtebbutt
Copy link
Author

gtebbutt commented Dec 2, 2024

Got it, and thanks for the quick follow up - I'll be fine running it directly from the branch for now, it should still save me a good amount of time being able to use with my code as-is.

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

No branches or pull requests

2 participants