This is an automated email from the ASF dual-hosted git repository.

rubys pushed a commit to branch master
in repository https://git-dual.apache.org/repos/asf/whimsy.git

The following commit(s) were added to refs/heads/master by this push:
       new  2e7b3b0   complete SVN.update functionality for directories
2e7b3b0 is described below

commit 2e7b3b0a23f1f1ea8a5bb870077282ca810201b9
Author: Sam Ruby <ru...@intertwingly.net>
AuthorDate: Thu May 19 10:16:42 2016 -0400

    complete SVN.update functionality for directories
---
 lib/whimsy/asf/svn.rb                          | 38 ++++++++++++++++++--------
 www/board/agenda/views/actions/publish.json.rb | 37 ++++++++++++-------------
 2 files changed, 45 insertions(+), 30 deletions(-)

diff --git a/lib/whimsy/asf/svn.rb b/lib/whimsy/asf/svn.rb
index bbf66d0..fe8160a 100644
--- a/lib/whimsy/asf/svn.rb
+++ b/lib/whimsy/asf/svn.rb
@@ -92,10 +92,16 @@ module ASF
       return revision, content
     end
 
-    # update a file in SVN, working entirely in a temporary directory
+    # update a file or directory in SVN, working entirely in a temporary
+    # directory
     def self.update(path, msg, env, _, options={})
-      dir = File.dirname(path)
-      basename = File.basename(path)
+      if File.directory? path
+        dir = path
+        basename = nil
+      else
+        dir = File.dirname(path)
+        basename = File.basename(path)
+      end
 
       if path.start_with? '/' and not path.include? '..' and File.exist?(path)
         dir.untaint
@@ -103,7 +109,6 @@ module ASF
       end
       
       tmpdir = Dir.mktmpdir.untaint
-      tmpfile = File.join(tmpdir, basename).untaint
 
       begin
         # create an empty checkout
@@ -112,15 +117,26 @@ module ASF
           `svn info #{dir}`[/URL: (.*)/, 1], tmpdir]
 
         # retrieve the file to be updated (may not exist)
-        _.system ['svn', 'update',
-          ['--username', env.user, '--password', env.password],
-          tmpfile]
+       if basename
+          tmpfile = File.join(tmpdir, basename).untaint
+          _.system ['svn', 'update',
+            ['--username', env.user, '--password', env.password],
+            tmpfile]
+       else
+         tmpfile = nil
+       end
 
         # determine the new contents
-        if File.file? tmpfile
+       if not tmpfile
+         # updating a directory
+          previous_contents = contents = nil
+          yield tmpdir, ''
+        elsif File.file? tmpfile
+         # updating an existing file
           previous_contents = File.read(tmpfile)
           contents = yield tmpdir, File.read(tmpfile)
         else
+         # updating a new file
           previous_contents = nil
           contents = yield tmpdir, ''
         end
@@ -133,7 +149,7 @@ module ASF
               ['--username', env.user, '--password', env.password],
               tmpfile]
           end
-        elsif File.file? tmpfile
+        elsif tmpfile and File.file? tmpfile
           File.unlink tmpfile
           _.system ['svn', 'delete',
             ['--username', env.user, '--password', env.password],
@@ -147,12 +163,12 @@ module ASF
           # commit the changes
           rc = _.system ['svn', 'commit', '--message', msg.untaint,
             ['--username', env.user, '--password', env.password],
-            tmpfile]
+            tmpfile || tmpdir]
         end
 
         # fail if there are pending changes
         unless rc == 0 and `svn st`.empty?
-          raise "svn failure #{File.join(svn, basename)}"
+          raise "svn failure #{path.inspect}"
         end
       ensure
         FileUtils.rm_rf tmpdir
diff --git a/www/board/agenda/views/actions/publish.json.rb 
b/www/board/agenda/views/actions/publish.json.rb
index 2e77c26..c9f21e8 100755
--- a/www/board/agenda/views/actions/publish.json.rb
+++ b/www/board/agenda/views/actions/publish.json.rb
@@ -44,20 +44,19 @@ end
 calendar.sub! /^(\s*-\s+#{fdate}\s*\n)/, ''
 
 #Commit the Minutes
-ASF::SVN.update MINUTES, @message, env, _ do |tmpdir, old_contents|
-  tmp = File.join(tmpdir, File.basename(MINUTES), year.to_s).untaint
+ASF::SVN.update MINUTES, @message, env, _ do |tmpdir|
+  yeardir = File.join(tmpdir, year.to_s).untaint
+  _.system "svn up #{yeardir}"
 
-  unless Dir.exist? tmp
-    _.system "mkdir #{tmp}"
-    _.system "svn add #{tmp}"
+  unless Dir.exist? yeardir
+    _.system "mkdir #{yeardir}"
+    _.system "svn add #{yeardir}"
   end
 
-  if not File.exist? "#{year}/board_minutes_#{@date}.txt"
-    _.system "cp #{BOARD_PRIVATE}/board_minutes_#{@date}.txt #{tmp}"
-    _.system "svn add #{tmp}/board_minutes_#{@date}.txt"
+  if not File.exist? "#{yeardir}/board_minutes_#{@date}.txt"
+    _.system "cp #{BOARD_PRIVATE}/board_minutes_#{@date}.txt #{yeardir}"
+    _.system "svn add #{yeardir}/board_minutes_#{@date}.txt"
   end
-
-  nil
 end
 
 # Update the Calendar
@@ -68,18 +67,18 @@ if File.read(CALENDAR) != calendar
 end
 
 # Clean up board directory
-ASF::SVN.update BOARD_PRIVATE, @message, env, _ do |tmpdir, old_contents|
-  tmp = File.join(tmpdir, File.basename(BOARD_PRIVATE)).untaint
-
-  if File.exist? "#{tmp}/board_minutes_#{@date}.txt"
-    _.system "svn rm #{tmp}/board_minutes_#{@date}.txt"
+ASF::SVN.update BOARD_PRIVATE, @message, env, _ do |tmpdir|
+  _.system "svn up #{tmpdir}/board_minutes_#{@date}.txt"
+  if File.exist? "#{tmpdir}/board_minutes_#{@date}.txt"
+    _.system "svn rm #{tmpdir}/board_minutes_#{@date}.txt"
   end
   
-  if File.exist? "#{tmp}/board_agenda_#{@date}.txt"
-    _.system "svn mv #{tmp}/board_agenda_#{@date}.txt #{tmp}/archived_agendas"
+  _.system "svn up #{tmpdir}/board_agenda_#{@date}.txt"
+  if File.exist? "#{tmpdir}/board_agenda_#{@date}.txt"
+    _.system "svn up --depth empty #{tmpdir}/archived_agendas"
+    _.system "svn mv #{tmpdir}/board_agenda_#{@date}.txt " +
+      "#{tmpdir}/archived_agendas"
   end
-
-  nil
 end
 
 Dir.chdir(BOARD_PRIVATE) {Dir['board_minutes_*.txt'].sort}

-- 
To stop receiving notification emails like this one, please contact
['"commits@whimsical.apache.org" <commits@whimsical.apache.org>'].

Reply via email to