diff options
author | Jacob Vosmaer <contact@jacobvosmaer.nl> | 2013-07-19 12:16:54 +0200 |
---|---|---|
committer | Jacob Vosmaer <contact@jacobvosmaer.nl> | 2013-07-19 12:16:54 +0200 |
commit | 4de0ee3b8fbdbcc215b0e23ef87c7a97eadadafd (patch) | |
tree | 8e8b27355fb6cc2cf8d1d261bf93d557b1735fca /lib/gitlab_keys.rb | |
parent | c4c0885a90e61faa28e928e24565ee0f6bd4b425 (diff) | |
download | gitlab-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.rb | 7 |
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 |