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

How to rename files in MemFS? #452

Closed
pspot2 opened this issue Mar 10, 2021 · 3 comments · Fixed by #472
Closed

How to rename files in MemFS? #452

pspot2 opened this issue Mar 10, 2021 · 3 comments · Fixed by #472
Milestone

Comments

@pspot2
Copy link

pspot2 commented Mar 10, 2021

Hi,

there doesn't seem to be a way to rename files in MemFS without copying them around. Looks like MemFS tries to apply os.rename() if the file can be seen by the OS (which is not the case for MemFS). The only remaining way is to use something like fs.move that duplicates the file before removing the old one. On systems with limited memory this obviously doesn't work. Example: a MemFS with a total size of 10 GB and a single file of 8 GB lying on it. How to rename this file?

@lurch
Copy link
Contributor

lurch commented Mar 10, 2021

Hmmm, interesting point...

https://docs.pyfilesystem.org/en/latest/guide.html#moving-and-copying says "These move and copy methods are optimized where possible, and depending on the implementation, they may be more performant than reading and writing files.". However it looks like MemFS doesn't have optimised move or movedir methods and instead just drops through to the base fs.move, which as you note does a copy-then-delete.

I'm not familiar enough with the MemFS to know if there's a good reason why it doesn't provide optimised move / movedir methods though (and I don't have time to look into it ATM). But feel free to experiment and put a PR together... 😉

@willmcgugan
Copy link
Member

MemFs certainly could do a rename operation rather than a copy. It just hasn’t been implemented.

@althonos
Copy link
Member

This was implemented in #472, and will be available in v2.4.13 when it's released. Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants