summaryrefslogtreecommitdiff
path: root/lib/gitlab_keys.rb
diff options
context:
space:
mode:
authorJacob Vosmaer <contact@jacobvosmaer.nl>2013-07-19 12:16:54 +0200
committerJacob Vosmaer <contact@jacobvosmaer.nl>2013-07-19 12:16:54 +0200
commit4de0ee3b8fbdbcc215b0e23ef87c7a97eadadafd (patch)
tree8e8b27355fb6cc2cf8d1d261bf93d557b1735fca /lib/gitlab_keys.rb
parentc4c0885a90e61faa28e928e24565ee0f6bd4b425 (diff)
downloadgitlab-shell-4de0ee3b8fbdbcc215b0e23ef87c7a97eadadafd.tar.gz
Use Tempfile instead of `sed -i`
The syntax for `sed -i` is incompatible between GNU sed and BSD sed. By Tempfile from the Ruby standard library we can avoid using the `-i` option of sed.
Diffstat (limited to 'lib/gitlab_keys.rb')
-rw-r--r--lib/gitlab_keys.rb7
1 files changed, 5 insertions, 2 deletions
diff --git a/lib/gitlab_keys.rb b/lib/gitlab_keys.rb
index f554e50..dc54740 100644
--- a/lib/gitlab_keys.rb
+++ b/lib/gitlab_keys.rb
@@ -1,3 +1,4 @@
+require 'tempfile'
require_relative 'gitlab_config'
require_relative 'gitlab_logger'
@@ -35,8 +36,10 @@ class GitlabKeys
def rm_key
$logger.info "Removing key #{@key_id}"
- cmd = "sed -i '/shell #{@key_id}\"/d' #{auth_file}"
- system(cmd)
+ Tempfile.open('authorized_keys') do |temp|
+ cmd = "sed '/shell #{@key_id}\"/d' #{auth_file} > #{temp.path} && mv #{temp.path} #{auth_file}"
+ system(cmd)
+ end
end
def clear