[Feature][ActiveSypport::Cache::FileStore] Add method to delete temporary files and empty directories

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[Feature][ActiveSypport::Cache::FileStore] Add method to delete temporary files and empty directories

Николай Марков
ActiveSypport::Cache::FileStore can leave temporary files inside a cache directory. It uses File.atomic_write (link to code). And File.atomic_write uses Tempfile class (link to code) and creates temporary files to check file permissions.
So in the case of process crash (e.g. kill -9) there is a possibility that these files will leave there and will never be deleted (and it occurs on my work).

My proposition - 1) create a special method that will find all these files and will remove them or 2) use existed method ActiveSupport::Cache::FileStore#cleanup to remove these temporary files.
As a side effect it also can remove empty directories.

WDYT? I will create a PR if you agree that this feature is useful.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/rubyonrails-core.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-core/9467a1d7-940a-4231-88b8-353264ef72a9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [Feature][ActiveSypport::Cache::FileStore] Add method to delete temporary files and empty directories

Mohamed Wael Khobalatte
When will this method run? At write time? start up time? And more importantly, how would you know which files to remove? I didn't look at the code in too much detail, but it looks to me that it is using the cache key name as filename, so heavily user application dependent, so you could find yourself removing files that are part of an ongoing cache write. 

I don't know what your use case is, but you could also set the cache directory to something where you run the cleanup yourself, or, possibly, pass it to the kernel's own `/tmp`, which might remove it on reboot or if past a certain date (depends on the distribution). 

I could see this this running in Rails on a separate thread and probing the file's `mtime` before removing, but I am not sure the complexity is warranted. 

On Thu, Jul 18, 2019 at 8:26 PM Николай Марков <[hidden email]> wrote:
ActiveSypport::Cache::FileStore can leave temporary files inside a cache directory. It uses File.atomic_write (link to code). And File.atomic_write uses Tempfile class (link to code) and creates temporary files to check file permissions.
So in the case of process crash (e.g. kill -9) there is a possibility that these files will leave there and will never be deleted (and it occurs on my work).

My proposition - 1) create a special method that will find all these files and will remove them or 2) use existed method ActiveSupport::Cache::FileStore#cleanup to remove these temporary files.
As a side effect it also can remove empty directories.

WDYT? I will create a PR if you agree that this feature is useful.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/rubyonrails-core.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-core/9467a1d7-940a-4231-88b8-353264ef72a9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Wael Khobalatte

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/rubyonrails-core.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-core/CAEtiSckuNUvUzG2o_%3DtFi-wrtGAA8Vz8KDU27Pn%2BJGvuf1PGYw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.