whimsical-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject [whimsy] branch master updated: Use File.join for pathname construction
Date Sat, 13 Feb 2021 17:24:18 GMT
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 4f2d307  Use File.join for pathname construction
4f2d307 is described below

commit 4f2d30741720b11e3a8a3139a0d3eea4749560b7
Author: Sebb <sebb@apache.org>
AuthorDate: Sat Feb 13 17:24:08 2021 +0000

    Use File.join for pathname construction
---
 www/board/agenda/models/pending.rb                       | 2 +-
 www/board/agenda/routes.rb                               | 2 +-
 www/board/agenda/views/actions/budget.json.rb            | 2 +-
 www/board/agenda/views/actions/commit.json.rb            | 8 +++++---
 www/board/agenda/views/actions/draft.json.rb             | 2 +-
 www/board/agenda/views/actions/feedback.json.rb          | 2 +-
 www/board/agenda/views/actions/message.json.rb           | 2 +-
 www/board/agenda/views/actions/minute.json.rb            | 2 +-
 www/board/agenda/views/actions/potential-actions.json.rb | 2 +-
 www/fundraising/invoice.cgi                              | 5 +++--
 www/members/list-traffic.cgi                             | 3 ++-
 www/members/nominations.cgi                              | 3 ++-
 www/officers/list-traffic.cgi                            | 3 ++-
 13 files changed, 22 insertions(+), 16 deletions(-)

diff --git a/www/board/agenda/models/pending.rb b/www/board/agenda/models/pending.rb
index 0422f07..cc60ce1 100644
--- a/www/board/agenda/models/pending.rb
+++ b/www/board/agenda/models/pending.rb
@@ -4,7 +4,7 @@ class Pending
     # user ids may include '-'
     raise ArgumentError, "Unexpected user id #{user}" unless user =~ /\A[-\w]+\z/
 
-    "#{AGENDA_WORK}/#{user}.yml"
+    File.join(AGENDA_WORK, "#{user}.yml")
   end
 
   # fetch and parse a work file
diff --git a/www/board/agenda/routes.rb b/www/board/agenda/routes.rb
index 973d833..40bfcc5 100755
--- a/www/board/agenda/routes.rb
+++ b/www/board/agenda/routes.rb
@@ -239,7 +239,7 @@ def server
     role: pending['role'],
     directors: Hash[ASF::Service['board'].members.map {|person|
       initials = begin
-        YAML.load_file("#{AGENDA_WORK}/#{person.id}.yml")['initials']
+        YAML.load_file(File.join(AGENDA_WORK, "#{person.id}.yml"))['initials']
       rescue
         person.public_name.gsub(/[^A-Z]/, '').downcase
       end
diff --git a/www/board/agenda/views/actions/budget.json.rb b/www/board/agenda/views/actions/budget.json.rb
index 9fe0bf2..9b46267 100644
--- a/www/board/agenda/views/actions/budget.json.rb
+++ b/www/board/agenda/views/actions/budget.json.rb
@@ -5,7 +5,7 @@
 validate_board_file(@agenda)
 
 @minutes = @agenda.sub('_agenda_', '_minutes_')
-minutes_file = "#{AGENDA_WORK}/#{@minutes.sub('.txt', '.yml')}"
+minutes_file = File.join(AGENDA_WORK, @minutes.sub('.txt', '.yml'))
 
 if File.exist? minutes_file
   minutes = YAML.load_file(minutes_file) || {}
diff --git a/www/board/agenda/views/actions/commit.json.rb b/www/board/agenda/views/actions/commit.json.rb
index cacc45d..d9b542c 100644
--- a/www/board/agenda/views/actions/commit.json.rb
+++ b/www/board/agenda/views/actions/commit.json.rb
@@ -9,13 +9,15 @@ user = env.user
 # user ids may include '-'
 raise ArgumentError, "Unexpected user id #{user}" unless user =~ /\A[-\w]+\z/
 
-updates = YAML.load_file("#{AGENDA_WORK}/#{user}.yml")
+user_yaml = File.join(AGENDA_WORK, "#{user}.yml")
+user_bak = File.join(AGENDA_WORK, "#{user}.bak")
+updates = YAML.load_file(user_yaml)
 
 agenda_file = updates['agenda']
 
 Agenda.update(agenda_file, @message) do |agenda|
   # refetch to make sure the data is fresh (handles retries, locks, etc...)
-  updates = YAML.load_file("#{AGENDA_WORK}/#{user}.yml")
+  updates = YAML.load_file(user_yaml)
 
   approved = updates['approved']
   unapproved = updates['unapproved'] || []
@@ -191,7 +193,7 @@ end
 
 # backup pending file, then clear approved and comments lists
 _pending Pending.update(env.user) {|pending|
-  File.rename "#{AGENDA_WORK}/#{user}.yml", "#{AGENDA_WORK}/#{user}.bak"
+  File.rename user_yaml, user_bak
   pending['approved'].clear
   pending['unapproved'].clear
   pending['flagged'].clear
diff --git a/www/board/agenda/views/actions/draft.json.rb b/www/board/agenda/views/actions/draft.json.rb
index 95558dc..3394a28 100644
--- a/www/board/agenda/views/actions/draft.json.rb
+++ b/www/board/agenda/views/actions/draft.json.rb
@@ -4,7 +4,7 @@
 
 validate_board_file(@agenda)
 
-agenda_file = "#{FOUNDATION_BOARD}/#{@agenda}"
+agenda_file = File.join(FOUNDATION_BOARD, @agenda)
 minutes_file = agenda_file.sub('_agenda', '_minutes')
 
 ASF::SVN.update minutes_file, @message, env, _ do |tmpdir, old_contents|
diff --git a/www/board/agenda/views/actions/feedback.json.rb b/www/board/agenda/views/actions/feedback.json.rb
index 5a6a6ed..6ebd8c3 100644
--- a/www/board/agenda/views/actions/feedback.json.rb
+++ b/www/board/agenda/views/actions/feedback.json.rb
@@ -8,7 +8,7 @@ validate_board_file(@agenda)
 
 # fetch minutes
 @minutes = @agenda.sub('_agenda_', '_minutes_')
-minutes_file = "#{AGENDA_WORK}/#{@minutes.sub('.txt', '.yml')}"
+minutes_file = File.join(AGENDA_WORK, @minutes.sub('.txt', '.yml'))
 date = @agenda[/\d+_\d+_\d+/].gsub('_', '-')
 
 if File.exist? minutes_file
diff --git a/www/board/agenda/views/actions/message.json.rb b/www/board/agenda/views/actions/message.json.rb
index fee5293..fdd79c2 100644
--- a/www/board/agenda/views/actions/message.json.rb
+++ b/www/board/agenda/views/actions/message.json.rb
@@ -12,7 +12,7 @@ if @text.start_with? '/me '
   log[:text].sub! /^\/me\s+/, '*** '
   log[:type] = :info
 elsif @type == :chat
-  chat = "#{AGENDA_WORK}/#{@agenda.sub('.txt', '')}-chat.yml"
+  chat = File.join(AGENDA_WORK, "#{@agenda.sub('.txt', '')}-chat.yml")
   File.write(chat, YAML.dump([])) if not File.exist? chat
 
   File.open(chat, 'r+') do |file|
diff --git a/www/board/agenda/views/actions/minute.json.rb b/www/board/agenda/views/actions/minute.json.rb
index f1f8395..b96d1b8 100644
--- a/www/board/agenda/views/actions/minute.json.rb
+++ b/www/board/agenda/views/actions/minute.json.rb
@@ -6,7 +6,7 @@ require 'active_support/core_ext/time'
 validate_board_file(@agenda)
 
 @minutes = @agenda.sub('_agenda_', '_minutes_')
-minutes_file = "#{AGENDA_WORK}/#{@minutes.sub('.txt', '.yml')}"
+minutes_file = File.join(AGENDA_WORK, @minutes.sub('.txt', '.yml'))
 
 if File.exist? minutes_file
   minutes = YAML.load_file(minutes_file) || {}
diff --git a/www/board/agenda/views/actions/potential-actions.json.rb b/www/board/agenda/views/actions/potential-actions.json.rb
index 7e79b9f..61bcb78 100644
--- a/www/board/agenda/views/actions/potential-actions.json.rb
+++ b/www/board/agenda/views/actions/potential-actions.json.rb
@@ -11,7 +11,7 @@ actions = parsed.find {|item| item['title'] == 'Action Items'}['actions']
 pattern = /^(?:@|AI\s+)(\w+):?\s+([\s\S]*?)(?:\n\n|$)/m
 minutes = File.basename(base).sub('agenda', 'minutes').sub('.txt', '.yml')
 date = minutes[/\d{4}_\d\d_\d\d/].gsub('_', '-')
-minutes = YAML.load_file("#{AGENDA_WORK}/#{minutes}") rescue {}
+minutes = YAML.load_file(File.join(AGENDA_WORK, minutes)) rescue {}
 minutes.each do |title, secnotes|
   next unless secnotes.is_a? String
   secnotes.scan(pattern).each do |owner, text|
diff --git a/www/fundraising/invoice.cgi b/www/fundraising/invoice.cgi
index 1018327..54c67f7 100755
--- a/www/fundraising/invoice.cgi
+++ b/www/fundraising/invoice.cgi
@@ -15,8 +15,9 @@ end
 
 HISTORY = '/var/tools/invoice'
 if %r{/(?<invoice>\d+)(\.\w+)?$} =~ ENV['PATH_INFO']
-  if File.exist? "#{HISTORY}/#{invoice}"
-    form = YAML.load_file("#{HISTORY}/#{invoice}")
+  invoice_path = File.join(HISTORY, invoice)
+  if File.exist? invoice_path
+    form = YAML.load_file(invoice_path)
     ENV['QUERY_STRING'] =
       form.map {|k,v| "#{k}=#{CGI.escape(v.first)}"}.join("&") if form
   end
diff --git a/www/members/list-traffic.cgi b/www/members/list-traffic.cgi
index b0cb796..59024c8 100755
--- a/www/members/list-traffic.cgi
+++ b/www/members/list-traffic.cgi
@@ -23,7 +23,8 @@ end
 ENV['HTTP_ACCEPT'] = 'application/json' if ENV['QUERY_STRING'].include? 'json'
 
 LIST_ROOT = 'members'
-SRV_MAIL = "/srv/mail/#{LIST_ROOT}"
+MAIL_ROOT = '/srv/mail' # TODO: this should be config item
+SRV_MAIL = File.join(MAIL_ROOT, LIST_ROOT)
 
 WEEK_TOTAL = '@@total' # Use @@ so it can't match who name/emails
 WEEK_START = '@@start'
diff --git a/www/members/nominations.cgi b/www/members/nominations.cgi
index e5a31a4..e539f31 100755
--- a/www/members/nominations.cgi
+++ b/www/members/nominations.cgi
@@ -15,12 +15,13 @@ MBOX = 'https://mail-search.apache.org/members/private-arch/members/'
 # link to roster page
 ROSTER = '/roster/committer'
 MEETINGS = ASF::SVN['Meetings']
+MAIL_ROOT = '/srv/mail' # TODO: this should be config item
 
 # Encapsulate gathering data to improve error processing
 def setup_data
   # get a list of current year's members@ emails
   year = Time.new.year.to_s
-  archive = Dir["/srv/mail/members/#{year}*/*"]
+  archive = Dir[File.join(MAIL_ROOT, "members", "#{year}*", "*")]
 
   # select messages that have a subject line starting with [MEMBER NOMINATION]
   emails = []
diff --git a/www/officers/list-traffic.cgi b/www/officers/list-traffic.cgi
index c0afe05..cce8c18 100755
--- a/www/officers/list-traffic.cgi
+++ b/www/officers/list-traffic.cgi
@@ -21,8 +21,9 @@ end
 # Return sorted data in JSON format if the query string includes 'json'
 ENV['HTTP_ACCEPT'] = 'application/json' if ENV['QUERY_STRING'].include? 'json'
 
+MAIL_ROOT = '/srv/mail' # TODO: this should be config item
 LIST_ROOT = 'board'
-SRV_MAIL = "/srv/mail/#{LIST_ROOT}"
+SRV_MAIL = File.join(MAIL_ROOT, LIST_ROOT)
 
 WEEK_TOTAL = '@@total' # Use @@ so it can't match who name/emails
 WEEK_START = '@@start'


Mime
View raw message