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

14 views
Skip to first unread message

Николай Марков

unread,
Jul 18, 2019, 8:26:34 PM7/18/19
to Ruby on Rails: Core
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.

Mohamed Wael Khobalatte

unread,
Jul 18, 2019, 9:30:29 PM7/18/19
to rubyonra...@googlegroups.com
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. 

--
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 rubyonrails-co...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
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

Reply all
Reply to author
Forward
0 new messages