Project

General

Profile

Actions

Bug #30639

closed

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 over 4 years ago. Updated almost 4 years ago.

Status:
Closed
Priority:
Normal
Category:
-
Target version:
-
Difficulty:
Triaged:
Yes
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 1 (0 open1 closed)

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

Updated by Peter Bray over 4 years ago

Sorry I forgot to preview the formatted version :-(

Actions #2

Updated by Peter Bray over 4 years 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"

Actions #3

Updated by Peter Bray over 4 years 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)

Actions #4

Updated by Peter Bray over 4 years 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 !!!

Actions #5

Updated by Oleh Fedorenko almost 4 years ago

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

Updated by Oleh Fedorenko almost 4 years ago

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

Updated by The Foreman Bot almost 4 years ago

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

Updated by The Foreman Bot almost 4 years ago

  • Fixed in Releases hammer-cli-2.4.0 added
Actions #9

Updated by Oleh Fedorenko almost 4 years ago

  • Status changed from Ready For Testing to Closed
Actions

Also available in: Atom PDF