In MySQL there’s this nice thing - “temporary tables”, you create a table with the session’s scope and you don’t have to clean it when you’re done.
In the file system, there’s File::createTmpFile() which creates a regular file in the temporary folder.
So I have these questions about this issue:
- Is that acceptable for me not to delete those files, and hope the the user / OS will do that at some point?
- If I should clean after me, should I take care for those cases in which my app crashes before cleanup ?
- Is there any way to really create files with a process scope?
I don’t know of any OSes that provide a bulletproof way to remove files when the process quits (or crashes), but the TemporaryFile class does its best to emulate that kind of behaviour.
Ha! Now that must have been there for some time as I see it in the online docs. SO HOW HAVE I NOT NOTICED??
I basically wrote this class for my own purposes not too long ago! It has the exact same functionality, though it does also a couple of extra functions, e.g. to check to see if it actually needs to be copied (i.e. if both files are identical, you don’t need to do anything), or if the target file is read-only [e.g. SVN locked]. Particularly useful when working on something that exports lots of data into an SVN asset folder, etc…
Some OSes keep the temp directory in memory (solaris does that, some linux distros do that). It’s a good way to clean stuff up, each reboot the temp directory gets purged no questions asked. Wish that windows could do that but i don’t know of any way to mount a piece of memory as a directory (under dos there used be a ramdisk command don’t knwo how modern widoze do that).
I think it’s a good idea cause it’s fast, but there is one thing to remember, you need to make sure it’s limited to a certain size.
[quote=“haydxn”]Ha! Now that must have been there for some time as I see it in the online docs. SO HOW HAVE I NOT NOTICED??[/quote] +1