Project

General

Profile

Bug #30639

hammer prebuild-bash-completion create a directories '~' and '~/.cache' in user's home directory AND stores JSON in a .yml file

Added by Peter Bray about 1 year ago. Updated 9 months ago.

Status:
Closed
Priority:
Normal
Category:
-
Target version:
-
Difficulty:
Triaged:
Yes
Bugzilla link:
Team Backlog:
Fixed in Releases:
Found in Releases:
In Kanboard:

Description

Package: rubygem-hammer_cli.noarch 2.1.1-1.el8

Running 'hammer prebuild-bash-completion' create a subdirectory name '~' of the user's home directory and than creates a '.cache' directory under that.

Example: On CentOS 8.2 System (hostname redacted)

[admin@centos8-host ]$ cd
[admin@centos8-host ~]$ touch . # So its lists last
[admin@centos8-host ~]$ ls ltra | tail -1
drwx-----
. 7 admin admin 4096 Aug 12 18:22 .
[admin@centos8-host ~]$ hammer prebuild-bash-completion
environment command is deprecated and will be removed in one of the future versions. Please use puppet-environment command instead.
report command is deprecated and will be removed in one of the future versions. Please use config-report command instead.
[admin@centos8-host ~]$ ls -ltra | tail -1
drwxrwxr-x. 3 admin admin 20 Aug 12 18:22 ~
[admin@centos8-host ~]$ find ./
-ls
67519951 0 drwxrwxr-x 3 admin admin 20 Aug 12 18:22 ./~
100919321 0 drwxrwxr-x 2 admin admin 6 Aug 12 18:22 ./~/.cache
[admin@centos8-host ]$ rm -rfv ./
removed directory './~/.cache'
removed directory './~'

Looking at /usr/share/gems/gems/hammer_cli-2.1.1/lib/hammer_cli/bash/prebuild_command.rb (shown below), either setting cache_file needs to under go tilde (~) expansion before being used passed to dirname(), or another cause needs to be investigated.

Regards,
Peter

module HammerCLI
module Bash
class PrebuildCompletionCommand < HammerCLI::AbstractCommand
def execute
map = HammerCLI::MainCommand.completion_map
cache_file = HammerCLI::Settings.get(:completion_cache_file)
cache_dir = File.dirname(cache_file)
FileUtils.mkdir_p(cache_dir) unless File.directory?(cache_dir)
File.write(File.expand_path(cache_file), map.to_json)

HammerCLI::EX_OK
end
end
end
HammerCLI::MainCommand.subcommand(
'prebuild-bash-completion',
_('Prepare map of options and subcommands for Bash completion'),
HammerCLI::Bash::PrebuildCompletionCommand
)
end

Related issues

Has duplicate Hammer CLI - Bug #31463: hammer(1) bash completion spews errors over the command line - Failure to expand '~' in the default configurationDuplicate

Associated revisions

Revision 99522f13 (diff)
Added by Oleh Fedorenko 11 months ago

Fixes #30639 - Expand path for bash completion file

Revision 6b192a9d
Added by Shira Maximov 9 months ago

Merge pull request #338 from ofedoren/bug-30639-bash-completion

Fixes #30639 - Expand path for bash completion file

History

#1 Updated by Peter Bray about 1 year ago

Sorry I forgot to preview the formatted version :-(

#2 Updated by Peter Bray about 1 year ago

The solution would appear to be File.expand_path()

echo 'File.expand_path("~/.cache")' | irb
Switch to inspect mode.
File.expand_path("~/.cache")
"/home/admin/.cache"

#3 Updated by Peter Bray about 1 year ago

I was going to stop at reporting this, but curiosity got the better of me ;-)

As File.expand_path() can fail if given rubbish input like "~~/.cache", I placed the call on its own, so any stack trace should show the problem is with the setting's value and not getting the setting, but I have never written a single line of Ruby before this, so I'm not going to suggest its the final or best solution, but it does seem to work, and the ~/.cache/hammer_completion.yml file is created and populated, without the errant directories being created :-)

--- /usr/share/gems/gems/hammer_cli-2.1.1/lib/hammer_cli/bash/prebuild_command.rb.orig    2020-06-03 05:33:03.000000000 +1000
+++ /usr/share/gems/gems/hammer_cli-2.1.1/lib/hammer_cli/bash/prebuild_command.rb    2020-08-12 18:52:42.696778829 +1000
@@ -4,6 +4,7 @@
       def execute
         map = HammerCLI::MainCommand.completion_map
         cache_file = HammerCLI::Settings.get(:completion_cache_file)
+        cache_file = File.expand_path(cache_file)
         cache_dir = File.dirname(cache_file)
         FileUtils.mkdir_p(cache_dir) unless File.directory?(cache_dir)
         File.write(File.expand_path(cache_file), map.to_json)

#4 Updated by Peter Bray about 1 year ago

  • Subject changed from hammer prebuild-bash-completion create a directories '~' and '~/.cache' in user's home directory to hammer prebuild-bash-completion create a directories '~' and '~/.cache' in user's home directory AND stores JSON in a .yml file

OK, so I just read the rest of the code in original post.

QUESTION: Why is JSON code being placed ~/.cache/hammer_completion.yml (a YAML file extension)?

And, yes I verified the contents of the file - its JSON and not YAML !!!

#5 Updated by Oleh Fedorenko 11 months ago

  • Has duplicate Bug #31463: hammer(1) bash completion spews errors over the command line - Failure to expand '~' in the default configuration added

#6 Updated by Oleh Fedorenko 11 months ago

  • Triaged changed from No to Yes
  • Assignee set to Oleh Fedorenko
  • Status changed from New to Assigned

#7 Updated by The Foreman Bot 11 months ago

  • Status changed from Assigned to Ready For Testing
  • Pull request https://github.com/theforeman/hammer-cli/pull/338 added

#8 Updated by The Foreman Bot 9 months ago

  • Fixed in Releases hammer-cli-2.4.0 added

#9 Updated by Oleh Fedorenko 9 months ago

  • Status changed from Ready For Testing to Closed

Also available in: Atom PDF