From: jiil.hyoun Date: Fri, 15 Mar 2013 02:02:36 +0000 (+0900) Subject: [Title] change file lock to mutex for client cache X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=763322d18ed30134af9488430c18a29bf26a1d74;p=sdk%2Ftools%2Fsdk-build.git [Title] change file lock to mutex for client cache [Type] Enhancement [Module] Toolchain / [Priority] Major [Jira#] [Redmine#] [Problem] [Cause] [Solution] [TestCase] Change-Id: Icec96d817bdd13a9b5ac713e3f392042b900463c --- diff --git a/src/pkg_server/client.rb b/src/pkg_server/client.rb index e59564b..f9cb174 100644 --- a/src/pkg_server/client.rb +++ b/src/pkg_server/client.rb @@ -48,6 +48,7 @@ require 'digest' $update_mutex = Mutex.new $get_snapshot_mutex = Mutex.new +$cache_mutex = Mutex.new class Client # constant @@ -163,13 +164,8 @@ class Client 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(", ")}" - begin - lock = Utils.file_lock(File.join(CONFIG_PATH,"cache_lock")) - FileUtils.rm_rf remove_list - rescue Exception => e - @log.error( e.message, Log::LV_USER) - ensure - Utils.file_unlock(lock) + $cache_mutex.synchronize do + FileUtils.rm_rf remove_list end end end @@ -359,17 +355,12 @@ class Client private def get_file_from_cache(filename, pkg_checksum, pkg_size, location) downloaded_file_path = nil - begin - lock = Utils.file_lock(File.join(CONFIG_PATH,"cache_lock")) - cached_filepath = get_cached_filepath(filename, pkg_checksum, pkg_size) - if not cached_filepath.nil? then - FileUtils.cp(cached_filepath, location) - downloaded_file_path = File.join(location, File.basename(cached_filepath)) - end - rescue Exception => e - @log.error( e.message, Log::LV_USER) - ensure - Utils.file_unlock(lock) + $cache_mutex.synchronize do + cached_filepath = get_cached_filepath(filename, pkg_checksum, pkg_size) + if not cached_filepath.nil? then + FileUtils.cp(cached_filepath, location) + downloaded_file_path = File.join(location, File.basename(cached_filepath)) + end end if not downloaded_file_path.nil? and not File.exist? downloaded_file_path then downloaded_file_path = nil