Skip to content

Commit

Permalink
Make clear_cache safe if no completion file is set (#386)
Browse files Browse the repository at this point in the history
If it returns nil, expand_path fails. It also replaces a file deletion
race condition with an atomic remove.
  • Loading branch information
ekohl authored Jul 3, 2024
1 parent 12d8edd commit d72facc
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/hammer_cli/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ def self.tty?
end

def self.clear_cache
cache_file = File.expand_path(HammerCLI::Settings.get(:completion_cache_file))
File.delete(cache_file) if File.exist?(cache_file)
if (completion_file = HammerCLI::Settings.get(:completion_cache_file))
FileUtils.rm_f(File.expand_path(completion_file))
end
end

def self.interactive?
Expand Down

0 comments on commit d72facc

Please sign in to comment.