- S-Core Co., Ltd
=end
require 'rbconfig'
+require 'find'
class Utils
STARTUP_INFO_SIZE = 68
end
+ def Utils.get_sub_files_info(path_list) # return [PATH,size,time] list
+ list = []
+ path_list.each do |path|
+ Find.find(path) do |dep_path|
+ if (File.exist?(dep_path) and not File.directory? dep_path)
+ fsize = File.size(dep_path)
+ ftime = File.new(dep_path).ctime
+ list.push [dep_path,fsize,ftime]
+ end
+ end
+ end
+ return list.sort {|a,b| a[2] <=> b[2]}
+ end
+
+
def Utils.get_directory_size(path)
os_category = get_os_category(HOST_OS)
if not File.exist? @location then FileUtils.mkdir_p "#{@location}" end
@log.info "Update local package list.. [#{@location}]"
read_installed_pkg_list()
+
+ #cache_size = 4G
+ @cache_size = 4000 #(MB)
+ end
+
+
+ # make cache clean
+ def clean_cache
+ #get dir info
+ cache_list = Dir.entries(CONFIG_PATH).select{|dir| not dir.start_with? "." and File.directory? CONFIG_PATH + "/#{dir}/downloads" }.map{|dir| CONFIG_PATH + "/#{dir}/downloads"}
+ cache_info_list = Utils.get_sub_files_info(cache_list).reverse
+ cache_size = 0
+ cache_info_list.each {|file| cache_size += file[1]}
+
+ extra_size = cache_size - (@cache_size * 1024 * 1024)
+
+ if extra_size < 0 then return end
+
+ remove_list = []
+ while extra_size > 0 do
+ old_package = cache_info_list.pop
+ remove_list.push old_package[0]
+ extra_size -= old_package[1]
+ end
+
+ FileUtils.rm_rf remove_list
end
public
@log.info "Removed old package files.."
@log.info " * #{pkg_files[1..-1].join(", ")}"
end
+ clean_cache
end
private