mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 14:03:39 +08:00
FIX: Handle files removed between glob
and mtime
This commit is contained in:
parent
9ee77eae98
commit
7df688d108
|
@ -151,8 +151,14 @@ module FileStore
|
||||||
|
|
||||||
# Remove all but CACHE_MAXIMUM_SIZE most recent files
|
# Remove all but CACHE_MAXIMUM_SIZE most recent files
|
||||||
files = Dir.glob("#{CACHE_DIR}*")
|
files = Dir.glob("#{CACHE_DIR}*")
|
||||||
.sort_by { |f| File.mtime(f) }
|
files.sort_by! do |file|
|
||||||
.slice(0...-CACHE_MAXIMUM_SIZE)
|
begin
|
||||||
|
File.mtime(file)
|
||||||
|
rescue Errno::ENOENT
|
||||||
|
Time.new(0)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
files.pop(CACHE_MAXIMUM_SIZE)
|
||||||
|
|
||||||
FileUtils.rm(files, force: true)
|
FileUtils.rm(files, force: true)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user