Merge pull request #459 from warpc/438-remove_rsync_mount_from_app

[refs #438] Remove rsync mount and umount from platforms
This commit is contained in:
Vladimir Sharshov 2012-05-16 06:24:31 -07:00
commit 1550d7a59e
4 changed files with 37 additions and 23 deletions

View File

@ -28,8 +28,9 @@ class Platform < ActiveRecord::Base
after_update :freeze_platform
after_create lambda { mount_directory_for_rsync unless hidden? }
after_destroy lambda { umount_directory_for_rsync unless hidden? }
after_create lambda { symlink_directory unless hidden? }
after_destroy lambda { remove_symlink_directory unless hidden? }
after_update :update_owner_relation
scope :search_order, order("CHAR_LENGTH(name) ASC")
@ -67,7 +68,7 @@ class Platform < ActiveRecord::Base
build_path(name)
end
def mount_path
def symlink_path
Rails.root.join("public", "downloads", name)
end
@ -123,10 +124,10 @@ class Platform < ActiveRecord::Base
def change_visibility
if !self.hidden?
self.update_attribute(:visibility, 'hidden')
umount_directory_for_rsync
remove_symlink_directory
else
self.update_attribute(:visibility, 'open')
mount_directory_for_rsync
symlink_directory
end
end
@ -134,19 +135,18 @@ class Platform < ActiveRecord::Base
system("sudo mkdir -p -m 0777 #{path}")
end
def mount_directory_for_rsync
def symlink_directory
# umount_directory_for_rsync # TODO ignore errors
system("sudo mkdir -p -m 0777 #{mount_path}")
system("sudo mount --bind #{path} #{mount_path}")
system("mkdir -p -m 0777 #{symlink_path}")
system("ln -s #{path} #{symlink_path}")
Arch.all.each do |arch|
str = "country=Russian Federation,city=Moscow,latitude=52.18,longitude=48.88,bw=1GB,version=2011,arch=#{arch.name},type=distrib,url=#{public_downloads_url}\n"
File.open(File.join(mount_path, "#{name}.#{arch.name}.list"), 'w') {|f| f.write(str) }
File.open(File.join(symlink_path, "#{name}.#{arch.name}.list"), 'w') {|f| f.write(str) }
end
end
def umount_directory_for_rsync
system("sudo umount #{mount_path}")
system("sudo rm -Rf #{mount_path}")
def remove_symlink_directory
system("rm -Rf #{symlink_path}")
end
def update_owner_relation

View File

@ -304,7 +304,7 @@ ActiveRecord::Schema.define(:version => 20120512102707) do
t.integer "build_count", :default => 0, :null => false
end
add_index "projects", ["owner_id"], :name => "index_projects_on_name_and_owner_id_and_owner_type", :unique => true, :case_sensitive => false
add_index "projects", ["owner_id"], :name => "index_projects_on_name_and_owner_id_and_owner_type", :unique => true
create_table "register_requests", :force => true do |t|
t.string "name"
@ -312,8 +312,8 @@ ActiveRecord::Schema.define(:version => 20120512102707) do
t.string "token"
t.boolean "approved", :default => false
t.boolean "rejected", :default => false
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "interest"
t.text "more"
end
@ -368,13 +368,14 @@ ActiveRecord::Schema.define(:version => 20120512102707) do
t.string "email", :default => "", :null => false
t.string "encrypted_password", :limit => 128, :default => "", :null => false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.datetime "created_at"
t.datetime "updated_at"
t.text "ssh_key"
t.string "uname"
t.string "role"
t.string "language", :default => "en"
t.datetime "reset_password_sent_at"
t.integer "own_projects_count", :default => 0, :null => false
t.text "professional_experience"
t.string "site"

View File

@ -0,0 +1,13 @@
namespace :downloads do
desc "Migrate from mount to symlinks"
task :migrate => :environment do
Platform.opened.each do |pl|
system("sudo umount #{pl.symlink_path}")
system("sudo rm -Rf #{pl.symlink_path}")
pl.symlink_directory
end
end
end

View File

@ -34,8 +34,8 @@ def set_session_for(user=nil)
end
def stub_rsync_methods
any_instance_of(Platform, :mount_directory_for_rsync => true)
any_instance_of(Platform, :umount_directory_for_rsync => true)
any_instance_of(Platform, :symlink_directory => true)
any_instance_of(Platform, :remove_symlink_directory => true)
end
def test_git_commit(project)