Commit 6b9177ca0209b78398edb409f11bb7b4f5db7ca3
1 parent
2095780f
Exists in
master
and in
4 other branches
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
Showing
2 changed files
with
12 additions
and
10 deletions
Show diff stats
app/models/namespace.rb
... | ... | @@ -52,7 +52,7 @@ class Namespace < ActiveRecord::Base |
52 | 52 | |
53 | 53 | def ensure_dir_exist |
54 | 54 | unless dir_exists? |
55 | - system("mkdir -m 770 #{namespace_full_path}") | |
55 | + FileUtils.mkdir( namespace_full_path, mode: 0770 ) | |
56 | 56 | end |
57 | 57 | end |
58 | 58 | |
... | ... | @@ -71,11 +71,12 @@ class Namespace < ActiveRecord::Base |
71 | 71 | if File.exists?(new_path) |
72 | 72 | raise "Already exists" |
73 | 73 | end |
74 | - | |
75 | - if system("mv #{old_path} #{new_path}") | |
74 | + | |
75 | + begin | |
76 | + FileUtils.mv( old_path, new_path ) | |
76 | 77 | send_update_instructions |
77 | 78 | @require_update_gitolite = true |
78 | - else | |
79 | + rescue Exception => e | |
79 | 80 | raise "Namespace move error #{old_path} #{new_path}" |
80 | 81 | end |
81 | 82 | end |
... | ... | @@ -88,7 +89,7 @@ class Namespace < ActiveRecord::Base |
88 | 89 | |
89 | 90 | def rm_dir |
90 | 91 | dir_path = File.join(Gitlab.config.gitolite.repos_path, path) |
91 | - system("rm -rf #{dir_path}") | |
92 | + FileUtils.rm_r( dir_path, force: true ) | |
92 | 93 | end |
93 | 94 | |
94 | 95 | def send_update_instructions | ... | ... |
lib/gitlab/project_mover.rb
... | ... | @@ -16,7 +16,7 @@ module Gitlab |
16 | 16 | def execute |
17 | 17 | # Create new dir if missing |
18 | 18 | new_dir_path = File.join(Gitlab.config.gitolite.repos_path, new_dir) |
19 | - system("mkdir -m 770 #{new_dir_path}") unless File.exists?(new_dir_path) | |
19 | + FileUtils.mkdir( new_dir_path, mode: 0770 ) unless File.exists?(new_dir_path) | |
20 | 20 | |
21 | 21 | old_path = File.join(Gitlab.config.gitolite.repos_path, old_dir, "#{project.path}.git") |
22 | 22 | new_path = File.join(new_dir_path, "#{project.path}.git") |
... | ... | @@ -25,17 +25,18 @@ module Gitlab |
25 | 25 | raise ProjectMoveError.new("Destination #{new_path} already exists") |
26 | 26 | end |
27 | 27 | |
28 | - if system("mv #{old_path} #{new_path}") | |
28 | + begin | |
29 | + FileUtils.mv( old_path, new_path ) | |
29 | 30 | log_info "Project #{project.name} was moved from #{old_path} to #{new_path}" |
30 | 31 | true |
31 | - else | |
32 | + rescue Exception => e | |
32 | 33 | message = "Project #{project.name} cannot be moved from #{old_path} to #{new_path}" |
33 | - log_info "Error! #{message}" | |
34 | + log_info "Error! #{message} (#{e.message})" | |
34 | 35 | raise ProjectMoveError.new(message) |
35 | 36 | end |
36 | 37 | end |
37 | 38 | |
38 | - protected | |
39 | + protected | |
39 | 40 | |
40 | 41 | def log_info message |
41 | 42 | Gitlab::AppLogger.info message | ... | ... |