YUKI Hiroshi
null+****@clear*****
Tue Apr 28 21:20:24 JST 2015
YUKI Hiroshi 2015-04-28 21:20:24 +0900 (Tue, 28 Apr 2015) New Revision: d293182ebb8455079882244013e1edd0d459163e https://github.com/droonga/droonga-engine/commit/d293182ebb8455079882244013e1edd0d459163e Message: Extract logic to generate unique file path as an utility Modified files: lib/droonga/forward_buffer.rb lib/droonga/path.rb Modified: lib/droonga/forward_buffer.rb (+4 -8) =================================================================== --- lib/droonga/forward_buffer.rb 2015-04-28 20:26:00 +0900 (6dce6ee) +++ lib/droonga/forward_buffer.rb 2015-04-28 21:20:24 +0900 (102bb44) @@ -141,15 +141,11 @@ module Droonga forwarded end + MICRO_SECONDS_DECIMAL_PLACE = 6 + def create_buffered_message_path(time_stamp=Time.now) - timestamp_part = time_stamp.iso8601(6) - sametime_count = 0 - path = nil - begin - path = @data_directory + "#{timestamp_part}.#{sametime_count}#{SUFFIX}" - sametime_count += 1 - end while path.exist? - path + basename = time_stamp.iso8601(MICRO_SECONDS_DECIMAL_PLACE) + Path.unique_file_path(@data_directory, basename, SUFFIX) end def on_forward(message, destination) Modified: lib/droonga/path.rb (+13 -0) =================================================================== --- lib/droonga/path.rb 2015-04-28 20:26:00 +0900 (36478d1) +++ lib/droonga/path.rb 2015-04-28 21:20:24 +0900 (71eb04a) @@ -92,6 +92,19 @@ module Droonga now.hour, now.min, now.sec, now.nsec) serf_event_handler_errors + name end + + def unique_file_path(directory, basename, suffix) + directory = Pathname(directory) + basename = basename.sub(/\.\z/, "") + suffix = suffix.sub(/\A\./, "") + uniqueness_count = 0 + path = nil + begin + path = directory + "#{basename}.#{uniqueness_count}.#{suffix}" + uniqueness_count += 1 + end while path.exist? + path + end end end end -------------- next part -------------- HTML����������������������������...Download