lib/carrierwave/uploader/cache.rb in carrierwave-0.8.0 vs lib/carrierwave/uploader/cache.rb in carrierwave-0.9.0
- old
+ new
@@ -11,14 +11,14 @@
##
# Generates a unique cache id for use in the caching system
#
# === Returns
#
- # [String] a cache id in the format YYYYMMDD-HHMM-PID-RND
+ # [String] a cache id in the format TIMEINT-PID-RND
#
def self.generate_cache_id
- Time.now.strftime('%Y%m%d-%H%M') + '-' + Process.pid.to_s + '-' + ("%04d" % rand(9999))
+ Time.now.utc.to_i.to_s + '-' + Process.pid.to_s + '-' + ("%04d" % rand(9999))
end
module Uploader
module Cache
extend ActiveSupport::Concern
@@ -41,12 +41,12 @@
# This only works as long as you haven't done anything funky with your cache_dir.
# It's recommended that you keep cache files in one place only.
#
def clean_cached_files!(seconds=60*60*24)
Dir.glob(File.expand_path(File.join(cache_dir, '*'), CarrierWave.root)).each do |dir|
- time = dir.scan(/(\d{4})(\d{2})(\d{2})-(\d{2})(\d{2})/).first.map { |t| t.to_i }
- time = Time.utc(*time)
+ time = dir.scan(/(\d+)-\d+-\d+/).first.map { |t| t.to_i }
+ time = Time.at(*time)
if time < (Time.now.utc - seconds)
FileUtils.rm_rf(dir)
end
end
end
@@ -163,10 +163,10 @@
# We can override the full_original_filename method in other modules
alias_method :full_original_filename, :original_filename
def cache_id=(cache_id)
- raise CarrierWave::InvalidParameter, "invalid cache id" unless cache_id =~ /\A[\d]{8}\-[\d]{4}\-[\d]+\-[\d]{4}\z/
+ raise CarrierWave::InvalidParameter, "invalid cache id" unless cache_id =~ /\A[\d]+\-[\d]+\-[\d]{4}\z/
@cache_id = cache_id
end
def original_filename=(filename)
raise CarrierWave::InvalidParameter, "invalid filename" if filename =~ CarrierWave::SanitizedFile.sanitize_regexp