You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@whimsical.apache.org by se...@apache.org on 2022/05/03 16:21:11 UTC
[whimsy] branch master updated: Don't update the file unnecessarily
This is an automated email from the ASF dual-hosted git repository.
sebb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/whimsy.git
The following commit(s) were added to refs/heads/master by this push:
new b05fc4f9 Don't update the file unnecessarily
b05fc4f9 is described below
commit b05fc4f91e64bf2ff96456bc995d5db8b6ea0104
Author: Sebb <se...@apache.org>
AuthorDate: Tue May 3 17:21:05 2022 +0100
Don't update the file unnecessarily
---
tools/merge_subscriptions.rb | 37 +++++++++++++++++++++++--------------
1 file changed, 23 insertions(+), 14 deletions(-)
diff --git a/tools/merge_subscriptions.rb b/tools/merge_subscriptions.rb
index 2d1a1a11..45bca4da 100644
--- a/tools/merge_subscriptions.rb
+++ b/tools/merge_subscriptions.rb
@@ -24,7 +24,7 @@
# qmail.ids = read both files, and eliminate duplicates
# list-flags = read old file, storing in hash (dom+list); merge in new; write out merged
# list-start - copy from NEW directory at end of run
-# list-counts - is that needed? TODO
+# list-counts - merge (apart from total)
require 'find'
require 'fileutils'
@@ -56,24 +56,33 @@ def merge_files(old_host, new_host, out)
end
# merge list-flags
- flags = {}
- File.open(File.join(old_host, 'list-flags')).each do |line|
- parts = line.chomp.split(' ', 2)
- flags[parts[1]] = parts[0]
- end
+ old_flags = File.join(old_host, 'list-flags')
+ new_flags = File.join(new_host, 'list-flags')
+ out_flags = File.join(out, 'list-flags')
+ out_time = File.mtime(out_flags) rescue 0
+ # only update flags if they have changed
+ if File.mtime(old_flags) > out_time || File.mtime(new_flags) > out_time
+
+ flags = {}
+ File.open(old_flags).each do |line|
+ parts = line.chomp.split(' ', 2)
+ flags[parts[1]] = parts[0]
+ end
- File.open(File.join(new_host, 'list-flags')).each do |line|
- parts = line.chomp.split(' ', 2)
- flags[parts[1]] = parts[0]
- end
+ File.open(new_flags).each do |line|
+ parts = line.chomp.split(' ', 2)
+ flags[parts[1]] = parts[0]
+ end
- File.open(File.join(out, 'list-flags'), 'w') do |f|
- flags.sort.each do |k, v|
- f.puts "#{v} #{k}"
+ File.open(out_flags, 'w') do |f|
+ flags.sort.each do |k, v|
+ f.puts "#{v} #{k}"
+ end
end
+
end
- # Create links to new cache files as necessary
+ # Create links to new cache files as necessary
Find.find(File.join(new_host, 'cache')) do |path|
if File.file? path
targ = path.sub(new_host, out)