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

Feature request: love.filesystem.newTempFile #2024

Open
lolbinarycat opened this issue Feb 22, 2024 · 7 comments
Open

Feature request: love.filesystem.newTempFile #2024

lolbinarycat opened this issue Feb 22, 2024 · 7 comments
Labels
more info needed Further information is needed from the user

Comments

@lolbinarycat
Copy link

there are two ways this could be implemented:

  1. create a file in /tmp and delete it when the program exits as part of the cleanup hook
  2. emulate a file via an in-memory buffer. this could be used on platforms that don't have a ramdisk, although it is a bit more difficult since love2d files have a more complicated interface than lua files

additionally, some way to easily move a temporary file to a permanent file would be nice.

@slime73
Copy link
Member

slime73 commented Feb 22, 2024

What sort of things would you use this for?

I'm not sure I like the idea of having a step to clean up files, because LÖVE ultimately doesn't control how it closes (it may crash or be force-quit etc. depending on what people do.)

@slime73 slime73 added the more info needed Further information is needed from the user label Feb 25, 2024
@WolfWings
Copy link

Not the OP, but it sounds like they just want access to the platform-equivalent 'tmpfile' system call, which if used would mean there'd be no cleanup to register as the operating system itself would handle that.

Linux Windows Mac Android

I apologize but I'm not able to find a good direct link for a pre-built system call on Apple iOS devices to do this.

This is mostly used on desktop platforms for various purposes relating to building a file such as a game save then copying it over to a permanent location as a single operation when done, so that in case of a crash temporary files won't accumulate and won't corrupt the save game without having to assemble the whole save-file in memory first.

@slime73
Copy link
Member

slime73 commented Mar 14, 2024

Overall I'd rather implement exactly what people actually want/need rather than a more general temp file API - otherwise situations like this can happen libsdl-org/SDL#9256

That being said, from what I understand some uses of temp files are actually extremely hard or even impossible to do in a way that's atomic and safe across different platforms. I also don't want to add an API that seems like it's intended to be safe but actually can't be in practice. So we'd need to do a lot of research into the specifics of individual use cases before implementing anything, I think.

@WolfWings
Copy link

The only two I can think of that's a reasonably sane use, one would be the example I gave above honestly and the other a strained variation of it that doesn't map well to Lua semantics at all so I'll skip it.

Realistically since there's no piecemeal assembling of files in Love2D anyways only an atomic-ish "replace the whole file with this data" there's no way to really benefit from this, for all use-cases I can think of looking across all manner of game engines I'm poking at... the existing filesystem.write() just does what's needed.

If in doubt write to a fixed file for the purpose/phase in the code, then .write(.read()) to its final destination is as atomic as one can get in Love2D AFAIK?

@lolbinarycat
Copy link
Author

Realistically since there's no piecemeal assembling of files in Love2D

this hasn't been true for some time, see File:write and File:seek

@radgeRayden
Copy link

Fwiw on our game we had a numbered backup system for the purposes of safe save files, you don't necessarily need a temporary file; instead you rotate your files and do redundancy checks

@lolbinarycat
Copy link
Author

yeah, i was actually implementing a replay system, in my case i just write it to a certain position in the save dir.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
more info needed Further information is needed from the user
Projects
None yet
Development

No branches or pull requests

4 participants