[Title] change file lock to mutex for client cache
authorjiil.hyoun <jiil.hyoun@samsung.com>
Fri, 15 Mar 2013 02:02:36 +0000 (11:02 +0900)
committerjiil.hyoun <jiil.hyoun@samsung.com>
Fri, 15 Mar 2013 02:02:36 +0000 (11:02 +0900)
[Type] Enhancement
[Module] Toolchain /
[Priority] Major
[Jira#]
[Redmine#]
[Problem]
[Cause]
[Solution]
[TestCase]

Change-Id: Icec96d817bdd13a9b5ac713e3f392042b900463c

src/pkg_server/client.rb

index e59564bf3468f9eaa906b211414a85d29e9630a3..f9cb1740c2d949327afc8ab5c37793747943d400 100644 (file)
@@ -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