diff --git a/app/Storage/_Storage.rb b/app/Storage/_Storage.rb index 6d2dec4..8b024c2 100644 --- a/app/Storage/_Storage.rb +++ b/app/Storage/_Storage.rb @@ -366,7 +366,7 @@ def add_update(file) target_dir.upload_from_file(file.abs_path, nil, convert:false) end # *too many different errors: HTTPClient::KeepAliveDisconnected, Errno::ECONNRESET, Errno::ECONNREFUSED, Errno::ENETUNREACH, Google::Apis::TransmissionError, SocketError - rescue e + rescue StandardError => e # ( storage.quota over_used_space = storage.used_space - storage.quota - w(%Q{over_used_space=}+over_used_space.inspect) + w(%Q{over_used_space.hr=}+over_used_space.hr.inspect) + w(%Q{ storage.key=}+ storage.key.inspect) # find the best file_to_move file_name_to_move = nil + moved_file_size = nil min_size_diff = storage.used_space + 1 files_map.each do |some_file_name, some_file| next if some_file.storage != storage.key # we need only files on this storage @@ -192,11 +195,20 @@ def balance_if_needed if size_diff < min_size_diff min_size_diff = size_diff file_name_to_move = some_file_name + moved_file_size = some_file.size end end - file_to_move = get file_name_to_move - # it should find the best next storage and delete from the current one + w(%Q{ file_name_to_move=}+ file_name_to_move.inspect) + w(%Q{ moved_file_size.hr=}+ moved_file_size.hr.inspect) + # *fast_one used here to do not download file from cloud if it is awailable on LocalFS + # *we do not use tmp files if reading from LocalFS + tmp_dir = nil if fast_one.is_a?(Storage::LocalFS) + file_to_move = fast_one.get file_name_to_move, to:tmp_dir + # *it should find the best next storage and delete from the current one add_update file_to_move + + # delete tmp file + file_to_move.del! if tmp_dir end end end @@ -263,7 +275,7 @@ def free_space def update_stats @db.used = @array.files_map.values.sum{|_| _.storage == @key ? _.size : 0 } @db.used_MB = (@db.used.to_f / 1.MB).ceil - @db.used_perc = (@db.used.to_f / quota).round(2) if quota < Float::INFINITY + @db.used_perc = (@db.used.to_f / quota * 100).round(1) if quota < Float::INFINITY end end diff --git a/app/Sync.rb b/app/Sync.rb index 86e6ed2..f43445b 100644 --- a/app/Sync.rb +++ b/app/Sync.rb @@ -2419,7 +2419,7 @@ def fast_one def balance_if_needed storages.values.each do |_| - _.balance_if_needed if _.is_a? StorageArray + _.balance_if_needed(tmp_dir:@sync.tmp_dir, fast_one:fast_one) if _.is_a? StorageArray end end diff --git a/app/app_sample.rb b/app/app_sample.rb index 707f5bf..461fa15 100644 --- a/app/app_sample.rb +++ b/app/app_sample.rb @@ -186,10 +186,10 @@ def cmd dir_path: 'F:/FarDrive_storage', quota_MB: 700 }, - LocalFS_2( + LocalFS_2: { dir_path: 'G:/FarDrive_storage', quota_GB: 20 - ) + } }, array_2: { _config: { diff --git a/build.txt b/build.txt index ba714d8..1a90ba7 100644 --- a/build.txt +++ b/build.txt @@ -1 +1 @@ -21.09.09 \ No newline at end of file +21.09.10 \ No newline at end of file