Commit 6b9177ca authored by Koen Punt's avatar Koen Punt

replaced system() calls with FileUtils.* method

This also makes that 'mv: cannot stat `/ho..' is not shown in the test :)

consistent spacing

require fileutils

Revert "require fileutils"

This reverts commit 54313d3bbaa60cfc5b405be50cc00b7f6b0cb715.

new hash notation

FileUtils.mv in begin/rescue block
parent 2095780f
...@@ -52,7 +52,7 @@ class Namespace < ActiveRecord::Base ...@@ -52,7 +52,7 @@ class Namespace < ActiveRecord::Base
def ensure_dir_exist def ensure_dir_exist
unless dir_exists? unless dir_exists?
system("mkdir -m 770 #{namespace_full_path}") FileUtils.mkdir( namespace_full_path, mode: 0770 )
end end
end end
...@@ -71,11 +71,12 @@ class Namespace < ActiveRecord::Base ...@@ -71,11 +71,12 @@ class Namespace < ActiveRecord::Base
if File.exists?(new_path) if File.exists?(new_path)
raise "Already exists" raise "Already exists"
end end
if system("mv #{old_path} #{new_path}") begin
FileUtils.mv( old_path, new_path )
send_update_instructions send_update_instructions
@require_update_gitolite = true @require_update_gitolite = true
else rescue Exception => e
raise "Namespace move error #{old_path} #{new_path}" raise "Namespace move error #{old_path} #{new_path}"
end end
end end
...@@ -88,7 +89,7 @@ class Namespace < ActiveRecord::Base ...@@ -88,7 +89,7 @@ class Namespace < ActiveRecord::Base
def rm_dir def rm_dir
dir_path = File.join(Gitlab.config.gitolite.repos_path, path) dir_path = File.join(Gitlab.config.gitolite.repos_path, path)
system("rm -rf #{dir_path}") FileUtils.rm_r( dir_path, force: true )
end end
def send_update_instructions def send_update_instructions
......
...@@ -16,7 +16,7 @@ module Gitlab ...@@ -16,7 +16,7 @@ module Gitlab
def execute def execute
# Create new dir if missing # Create new dir if missing
new_dir_path = File.join(Gitlab.config.gitolite.repos_path, new_dir) new_dir_path = File.join(Gitlab.config.gitolite.repos_path, new_dir)
system("mkdir -m 770 #{new_dir_path}") unless File.exists?(new_dir_path) FileUtils.mkdir( new_dir_path, mode: 0770 ) unless File.exists?(new_dir_path)
old_path = File.join(Gitlab.config.gitolite.repos_path, old_dir, "#{project.path}.git") old_path = File.join(Gitlab.config.gitolite.repos_path, old_dir, "#{project.path}.git")
new_path = File.join(new_dir_path, "#{project.path}.git") new_path = File.join(new_dir_path, "#{project.path}.git")
...@@ -25,17 +25,18 @@ module Gitlab ...@@ -25,17 +25,18 @@ module Gitlab
raise ProjectMoveError.new("Destination #{new_path} already exists") raise ProjectMoveError.new("Destination #{new_path} already exists")
end end
if system("mv #{old_path} #{new_path}") begin
FileUtils.mv( old_path, new_path )
log_info "Project #{project.name} was moved from #{old_path} to #{new_path}" log_info "Project #{project.name} was moved from #{old_path} to #{new_path}"
true true
else rescue Exception => e
message = "Project #{project.name} cannot be moved from #{old_path} to #{new_path}" message = "Project #{project.name} cannot be moved from #{old_path} to #{new_path}"
log_info "Error! #{message}" log_info "Error! #{message} (#{e.message})"
raise ProjectMoveError.new(message) raise ProjectMoveError.new(message)
end end
end end
protected protected
def log_info message def log_info message
Gitlab::AppLogger.info message Gitlab::AppLogger.info message
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment