changeset 437:102056ec2de9 bug_169

Introduce a method on the sys controller to clear a repository cache; use a file in the mirror dir to notify the Ruby external repo script that it needs to call it
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Mon, 06 Jun 2011 13:31:44 +0100
parents 4eb486dbf730
children 34214e593c67 9e5828c6e55d
files app/controllers/sys_controller.rb app/models/repository.rb config/routes.rb extra/soundsoftware/convert-external-repos.rb extra/soundsoftware/update-external-repo.sh
diffstat 5 files changed, 28 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/app/controllers/sys_controller.rb	Mon Jun 06 12:53:06 2011 +0100
+++ b/app/controllers/sys_controller.rb	Mon Jun 06 13:31:44 2011 +0100
@@ -69,6 +69,16 @@
     render :nothing => true, :status => 404
   end
 
+  def clear_repository_cache
+    project = Project.find(params[:id])
+    if project.repository
+      project.repository.clear_cache
+    end
+    render :nothing => true, :status => 200
+  rescue ActiveRecord::RecordNotFound
+    render :nothing => true, :status => 404
+  end
+  
   def set_embedded_active
     project = Project.find(params[:id])
     mods = project.enabled_modules
--- a/app/models/repository.rb	Mon Jun 06 12:53:06 2011 +0100
+++ b/app/models/repository.rb	Mon Jun 06 13:31:44 2011 +0100
@@ -203,6 +203,10 @@
     nil
   end
   
+  def clear_cache
+    clear_changesets
+  end
+
   private
   
   def before_save
--- a/config/routes.rb	Mon Jun 06 12:53:06 2011 +0100
+++ b/config/routes.rb	Mon Jun 06 13:31:44 2011 +0100
@@ -237,8 +237,9 @@
   map.with_options :controller => 'sys' do |sys|
     sys.connect 'sys/projects.:format', :action => 'projects', :conditions => {:method => :get}
     sys.connect 'sys/projects/:id/repository.:format', :action => 'create_project_repository', :conditions => {:method => :post}
-    sys.connect 'sys/projects/:id/external-repository.:format', :action => 'get_external_repo_url', :conditions => {:method => :get}
+    sys.connect 'sys/projects/:id/external_repository.:format', :action => 'get_external_repo_url', :conditions => {:method => :get}
     sys.connect 'sys/projects/:id/embedded.:format', :action => 'set_embedded_active', :conditions => { :method => :post }
+    sys.connect 'sys/projects/:id/repository_cache.:format', :action => 'clear_repository_cache', :conditions => {:method => :post}
   end
  
   # Install the default route as the lowest priority.
--- a/extra/soundsoftware/convert-external-repos.rb	Mon Jun 06 12:53:06 2011 +0100
+++ b/extra/soundsoftware/convert-external-repos.rb	Mon Jun 06 13:31:44 2011 +0100
@@ -62,6 +62,8 @@
 $http_pass    = ''
 $test         = false
 
+$mirrordir    = '/var/mirror'
+
 def log(text, options={})
   level = options[:level] || 0
   puts text unless $quiet or level > $verbose
@@ -168,6 +170,14 @@
   end
 
   system($command, project.identifier, repos_path, external_url)
+  
+  $cache_clearance_file = File.join($mirrordir, project.identifier, 'url_changed')
+  if File.file?($cache_clearance_file)
+    log("\tproject repo url has changed, requesting cache clearance")
+    if project.post(:repository_cache, :key => $api_key)
+      File.delete($cache_clearance_file)
+    end
+  end
 
 end
   
--- a/extra/soundsoftware/update-external-repo.sh	Mon Jun 06 12:53:06 2011 +0100
+++ b/extra/soundsoftware/update-external-repo.sh	Mon Jun 06 13:31:44 2011 +0100
@@ -68,7 +68,7 @@
 successfile="$project_mirror/last_successful_url"
 if [ -f "$successfile" ]; then
     last=$(cat "$successfile")
-    if [ x"$last" == x"$remote_repo" ]; then
+    if [ x"$last" = x"$remote_repo" ]; then
 	echo "$$: Remote URL is unchanged from last successful update"
     else
 	echo "$$: Remote URL has changed since last successful update:"
@@ -78,6 +78,7 @@
 	mv "$project_repo_mirror" "$project_repo_mirror"."$suffix"
 	mv "$local_repo" "$local_repo"."$suffix"
 	mv "$successfile" "$successfile"."$suffix"
+	touch "$project_mirror/url_changed"
     fi
 fi