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,7 +52,7 @@ class Namespace < ActiveRecord::Base | ||
52 | 52 | ||
53 | def ensure_dir_exist | 53 | def ensure_dir_exist |
54 | unless dir_exists? | 54 | unless dir_exists? |
55 | - system("mkdir -m 770 #{namespace_full_path}") | 55 | + FileUtils.mkdir( namespace_full_path, mode: 0770 ) |
56 | end | 56 | end |
57 | end | 57 | end |
58 | 58 | ||
@@ -71,11 +71,12 @@ class Namespace < ActiveRecord::Base | @@ -71,11 +71,12 @@ class Namespace < ActiveRecord::Base | ||
71 | if File.exists?(new_path) | 71 | if File.exists?(new_path) |
72 | raise "Already exists" | 72 | raise "Already exists" |
73 | end | 73 | end |
74 | - | ||
75 | - if system("mv #{old_path} #{new_path}") | 74 | + |
75 | + begin | ||
76 | + FileUtils.mv( old_path, new_path ) | ||
76 | send_update_instructions | 77 | send_update_instructions |
77 | @require_update_gitolite = true | 78 | @require_update_gitolite = true |
78 | - else | 79 | + rescue Exception => e |
79 | raise "Namespace move error #{old_path} #{new_path}" | 80 | raise "Namespace move error #{old_path} #{new_path}" |
80 | end | 81 | end |
81 | end | 82 | end |
@@ -88,7 +89,7 @@ class Namespace < ActiveRecord::Base | @@ -88,7 +89,7 @@ class Namespace < ActiveRecord::Base | ||
88 | 89 | ||
89 | def rm_dir | 90 | def rm_dir |
90 | dir_path = File.join(Gitlab.config.gitolite.repos_path, path) | 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 | end | 93 | end |
93 | 94 | ||
94 | def send_update_instructions | 95 | def send_update_instructions |
lib/gitlab/project_mover.rb
@@ -16,7 +16,7 @@ module Gitlab | @@ -16,7 +16,7 @@ module Gitlab | ||
16 | def execute | 16 | def execute |
17 | # Create new dir if missing | 17 | # Create new dir if missing |
18 | new_dir_path = File.join(Gitlab.config.gitolite.repos_path, new_dir) | 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 | old_path = File.join(Gitlab.config.gitolite.repos_path, old_dir, "#{project.path}.git") | 21 | old_path = File.join(Gitlab.config.gitolite.repos_path, old_dir, "#{project.path}.git") |
22 | new_path = File.join(new_dir_path, "#{project.path}.git") | 22 | new_path = File.join(new_dir_path, "#{project.path}.git") |
@@ -25,17 +25,18 @@ module Gitlab | @@ -25,17 +25,18 @@ module Gitlab | ||
25 | raise ProjectMoveError.new("Destination #{new_path} already exists") | 25 | raise ProjectMoveError.new("Destination #{new_path} already exists") |
26 | end | 26 | end |
27 | 27 | ||
28 | - if system("mv #{old_path} #{new_path}") | 28 | + begin |
29 | + FileUtils.mv( old_path, new_path ) | ||
29 | log_info "Project #{project.name} was moved from #{old_path} to #{new_path}" | 30 | log_info "Project #{project.name} was moved from #{old_path} to #{new_path}" |
30 | true | 31 | true |
31 | - else | 32 | + rescue Exception => e |
32 | message = "Project #{project.name} cannot be moved from #{old_path} to #{new_path}" | 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 | raise ProjectMoveError.new(message) | 35 | raise ProjectMoveError.new(message) |
35 | end | 36 | end |
36 | end | 37 | end |
37 | 38 | ||
38 | - protected | 39 | + protected |
39 | 40 | ||
40 | def log_info message | 41 | def log_info message |
41 | Gitlab::AppLogger.info message | 42 | Gitlab::AppLogger.info message |