read_installed_pkg_list()
@configs = {}
- #default cache size = 4G
- @configs[:CACHE_SIZE] = "4000"
+ #default cache size = 8G
+ @configs[:CACHE_SIZE] = "8000"
end
# make cache clean
- #private
- #def remove_old_files_in_cache
- # #get dir info
- # cache_list = get_cache_dir_list
- # cache_info_list = Utils.get_sub_files_info(cache_list).sort {|a,b| a[3] <=> b[3]} # [path,size,ctime,mtime]
- # cache_size = 0
- # cache_info_list.each {|file| cache_size += file[1]}
-
- # read_configs
- # max_cache_size = get_config_max_cache_size
-
- # extra_size = cache_size - max_cache_size
-
- # if extra_size < 0 then return end
-
- # remove_list = []
- # while extra_size > 0 do
- # old_package = cache_info_list.shift
- # remove_list.push old_package[0]
- # extra_size -= old_package[1]
- # end
-
- # if not remove_list.empty? then
- # @log.info "Removed oldest package files.. (Now not fully caching)"
- # @log.info " * #{remove_list.map{|path| File.basename(path)}.join(", ")}"
- # $cache_mutex.synchronize do
- # FileUtils.rm_rf remove_list
- # end
- # end
- #end
+ private
+ def remove_old_files_in_cache
+ #get dir info
+ cache_list = get_cache_dir_list
+ cache_info_list = Utils.get_sub_files_info(cache_list).sort {|a,b| a[3] <=> b[3]} # [path,size,ctime,mtime]
+ cache_size = 0
+ cache_info_list.each {|file| cache_size += file[1]}
+
+ read_configs
+ max_cache_size = get_config_max_cache_size
+
+ extra_size = cache_size - max_cache_size
+
+ if extra_size < 0 then return end
+
+ remove_list = []
+ while extra_size > 0 do
+ old_package = cache_info_list.shift
+ remove_list.push old_package[0]
+ extra_size -= old_package[1]
+ end
+
+ if not remove_list.empty? then
+ @log.info "Removed oldest package files.. (Now not fully caching)"
+ @log.info " * #{remove_list.map{|path| File.basename(path)}.join(", ")}"
+ FileUtils.rm_rf remove_list
+ end
+ end
private
def get_cache_dir_list
private
def get_config_max_cache_size
- return (@configs[:CACHE_SIZE] =~ /^([0-9][0-9]*)$/i)? ($1.to_i * 1024 * 1024) : (4 * 1024 * 1024 * 1024) #default size 4G : unit = MB
+ return (@configs[:CACHE_SIZE] =~ /^([0-9][0-9]*)$/i)? ($1.to_i * 1024 * 1024) : (8 * 1024 * 1024 * 1024) #default size 4G : unit = MB
end
private
if not File.directory? location then return nil end
downloaded_file_path = nil
@log.info "Wait for cache sync",Log::LV_USER
- $cache_mutex.synchronize do
+ begin
+ lock = Utils.file_lock(File.join(CONFIG_PATH,".cache_lock"))
@log.info "Entering cache sync",Log::LV_USER
cached_filepath = get_cached_filepath(filename, pkg_checksum, pkg_size)
if not cached_filepath.nil? and File.exist? cached_filepath then
FileUtils.ln(cached_filepath, location, :force => true)
downloaded_file_path = File.join(location, File.basename(cached_filepath))
end
+ ensure
+ Utils.file_unlock(lock) if not lock.nil?
end
@log.info "Cache sync done",Log::LV_USER
if not downloaded_file_path.nil? and not File.exist? downloaded_file_path then
@log.info "Failed to move [#{filename}] to "
@log.info " [#{@download_path}]"
end
- #remove_old_files_in_cache
+
+ begin
+ lock = Utils.file_lock(File.join(CONFIG_PATH,".cache_lock"))
+
+ remove_old_files_in_cache
+ ensure
+ Utils.file_unlock(lock) if not lock.nil?
+ end
end
private