summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAlexis Reigel <mail@koffeinfrei.org>2017-09-13 11:31:37 +0000
committerRémy Coutable <remy@rymai.me>2017-09-13 11:31:37 +0000
commitbb1cf2aaf9d392ce9dfbe235af80d65719dbb343 (patch)
tree46cb0f3750926353431c1b4aeeb73e8eec7b54dd /lib
parent4fb6848fdb344ae996e7314ad07e0d11b78fd6d0 (diff)
downloadgitlab-ce-bb1cf2aaf9d392ce9dfbe235af80d65719dbb343.tar.gz
Fix: GPG tmp dir removal race condition
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/gpg.rb14
1 files changed, 10 insertions, 4 deletions
diff --git a/lib/gitlab/gpg.rb b/lib/gitlab/gpg.rb
index 025f826e65f..0d5039ddf5f 100644
--- a/lib/gitlab/gpg.rb
+++ b/lib/gitlab/gpg.rb
@@ -69,11 +69,17 @@ module Gitlab
def optimistic_using_tmp_keychain
previous_dir = current_home_dir
- Dir.mktmpdir do |dir|
- GPGME::Engine.home_dir = dir
- yield
- end
+ tmp_dir = Dir.mktmpdir
+ GPGME::Engine.home_dir = tmp_dir
+ yield
ensure
+ # Ignore any errors when removing the tmp directory, as we may run into a
+ # race condition:
+ # The `gpg-agent` agent process may clean up some files as well while
+ # `FileUtils.remove_entry` is iterating the directory and removing all
+ # its contained files and directories recursively, which could raise an
+ # error.
+ FileUtils.remove_entry(tmp_dir, true)
GPGME::Engine.home_dir = previous_dir
end
end