blackbox icon indicating copy to clipboard operation
blackbox copied to clipboard

blackbox doesnt handle spaces or () in directory names properly

Open evanccnyc opened this issue 9 years ago • 13 comments

It looks like blackbox doesnt like it when the directory name has spaces or ( in it. The initial command to add the file works but after that everything gets wonky.

blackbox_register_new_file cookbooks/test_base/attributes/secure.rb
========== PLAINFILE cookbooks/test_base/attributes/secure.rb
========== ENCRYPTED cookbooks/test_base/attributes/secure.rb.gpg
========== Importing keychain: START
gpg: Total number processed: 1
gpg:              unchanged: 1
========== Importing keychain: DONE
========== Encrypting: cookbooks/test_base/attributes/secure.rb
========== Encrypting: DONE
========== Adding file to list.
========== CREATED: cookbooks/test_base/attributes/secure.rb.gpg
========== UPDATING REPO:
NOTE: "already tracked!" messages are safe to ignore.
[postfix-config ce2d5b9] registered in blackbox: cookbooks/test_base/attributes/secure.rb
 2 files changed, 1 insertion(+)
 create mode 100644 cookbooks/test_base/attributes/secure.rb.gpg
========== UPDATING VCS: DONE
Local repo updated.  Please push when ready.
    git push

What is in gitignore:

.idea
.envrc

# Cookbook ignores
.vagrant
Berksfile.lock
*~
*#
.#*
\#*#
.*.sw[a-z]
*.un~

# Bundler
Gemfile.lock
bin/*
.bundle/*

.kitchen/
.kitchen.local.yml
/keyrings/live/pubring.gpg~
/keyrings/live/pubring.kbx~
/keyrings/live/secring.gpg
/Users/test/Dropbox (test)/base-ami/cookbooks/test_base/attributes/secure.rb

What is in blackbox-files.txt

/Users/test/Dropbox (test)/base-ami/cookbooks/test_base/attributes/secure.rb

What happens when you run a command:

blackbox_update_all_files
WARNING: You probably want to run gpg-agent as
you will be asked for your passphrase many times.
Example: $ eval $(gpg-agent --daemon)
Press CTRL-C now to stop. ENTER to continue:
========== blackbox administrators are:
[email protected]
jenkins-master
========== Importing keychain: START
gpg: Total number processed: 2
gpg:              unchanged: 2
========== Importing keychain: DONE
========== ENCRYPTED FILES TO BE RE-ENCRYPTED:
    cookbooks/test_base/attributes/secure.rb.gpg
========== FILES IN THE WAY:
All OK.
========== RE-ENCRYPTING FILES:
========== PROCESSING "cookbooks/test_base/attributes/secure.rb"
ERROR: cookbooks/test_base/attributes/secure.rb not found in /Users/test/Dropbox (test)/base-ami/keyrings/live/blackbox-files.txt
PWD=/Users/test/Dropbox/base-ami
Exiting...

Let me know if you need more information

evanccnyc avatar May 16 '16 17:05 evanccnyc

I'm surprised that blackbox-files.txt includes the entire path (/Users/test/Dropbox (test)/base-ami/cookbooks/test_base/attributes/secure.rb) instead of just cookbooks/test_base/attributes/secure.rb

What command was used to register the file?

tlimoncelli avatar May 16 '16 19:05 tlimoncelli

blackbox_register_new_file cookbooks/test_base/attributes/secure.rb

evanccnyc avatar May 16 '16 19:05 evanccnyc

If you fix blackbox-files.txt manually, does everything else work?

tlimoncelli avatar May 16 '16 19:05 tlimoncelli

@tlimoncelli unfortunately not, I get something like this:

blackbox_update_all_files
WARNING: You probably want to run gpg-agent as
you will be asked for your passphrase many times.
Example: $ eval $(gpg-agent --daemon)
Press CTRL-C now to stop. ENTER to continue:
========== blackbox administrators are:
[email protected]
jenkins-master
========== Importing keychain: START
gpg: Total number processed: 2
gpg:              unchanged: 2
========== Importing keychain: DONE
========== ENCRYPTED FILES TO BE RE-ENCRYPTED:
    cookbooks/test_base/attributes/secure.rb.gpg
========== FILES IN THE WAY:
All OK.

========== RE-ENCRYPTING FILES:
========== PROCESSING "cookbooks/test_base/attributes/secure.rb"
ERROR: cookbooks/test_base/attributes/secure.rb not found in /Users/test/Dropbox (test)/base-ami/keyrings/live/blackbox-files.txt

evanccnyc avatar May 16 '16 19:05 evanccnyc

I can't reproduce this problem. It should be in either vcs_relative_path(), get_unencrypted_filename() or get_encrypted_filename() but this test script doesn't demonstrate the problem:

#!/usr/bin/env bash

#
# _blackbox_common_test.sh -- Unit tests of functions from _blackbox_common.sh
#

set -e
. "${0%/*}/_blackbox_common.sh"
. /Users/tlimoncelli/gitwork/blackbox/tools/test_functions.sh

PHASE 'Test vcs_relative_path: TestA'
export REPOBASE='/Users/tlimoncelli/Applications (Parallels)/{fd2148c8-9fdd-11d5-bb16-d31daf3a6879} Applications.localized'
FILE='Microsoft  Windows Fax and Scan.app/Contents'
result=$(vcs_relative_path Contents)
echo result=XXX${result}XXX
if [[ $FILE != $result ]] ; then
  echo FAIL
fi

unencrypted_file=$(get_unencrypted_filename "${result}.gpg")
echo un=XXX${unencrypted_file}XXX
encrypted_file=$(get_encrypted_filename "${result}")
echo en=XXX${encrypted_file}XXX

echo '========== DONE.'

Can you reproduce the issue?

TomOnTime avatar May 17 '16 14:05 TomOnTime

@TomOnTime I couldnt get your script to work. I tried running it in the directory where I have blackbox and it just returned me to to the command line. I replaced your directories with my own. I am sure I am doing something wrong there.

I created a new repo from scratch with similar settings as my test case above and have the same errors. It does appear that I am able to run blackbox_edit_start and blackbox_edit_end no problem but blackbox_update_all_files has problems and of course the files have the whole path in blackbox-files.txt and .gitignore.

Some more details on my setup: Mac OS X 10.10 The actual directory I am in is also a symlink to the real directory:

lrwxr-xr-x    1 test  staff         18 Sep 17  2015 Dropbox -> Dropbox (test)
drwx------@ 124 test  staff       4216 May 17 10:52 Dropbox (test) 

evanccnyc avatar May 17 '16 15:05 evanccnyc

I'm on Mac OS X 10.11.5, but I doubt that's going to cause any differences. What happens when you run the script as: bash -x /path/to/script.sh

TomOnTime avatar May 17 '16 18:05 TomOnTime

@TomOnTime

+ set -e
+ . _blackbox_common.sh
++ exec /usr/local/Cellar/blackbox/1.20160122/libexec/_blackbox_common.sh

evanccnyc avatar May 17 '16 18:05 evanccnyc

Check the lines that look like this and make sure they start with ". " (dot space):

set -e
. "${0%/*}/_blackbox_common.sh"
. /Users/tlimoncelli/gitwork/blackbox/tools/test_functions.sh

TomOnTime avatar May 17 '16 19:05 TomOnTime

set -e
. "${0%/*}/_blackbox_common.sh"
. /Users/test/work/blackbox/tools/test_functions.sh

PHASE 'Test vcs_relative_path: TestA'
export REPOBASE='/Users/test/work/test (test)/test'
FILE='foo.txt'
result=$(vcs_relative_path Contents)
echo result=XXX${result}XXX
if [[ $FILE != $result ]] ; then
  echo FAIL
fi

unencrypted_file=$(get_unencrypted_filename "${result}.gpg")
echo un=XXX${unencrypted_file}XXX
encrypted_file=$(get_encrypted_filename "${result}")
echo en=XXX${encrypted_file}XXX

echo '========== DONE.'

Now returns:

+ set -e
+ . blackboxtest.sh/_blackbox_common.sh
blackboxtest.sh: line 2: blackboxtest.sh/_blackbox_common.sh: Not a directory

evanccnyc avatar May 17 '16 19:05 evanccnyc

Try changing . "${0%/*}/_blackbox_common.sh" to . /the/path/to/_blackbox_common.sh (i.e. the actual path to the file).

TomOnTime avatar May 18 '16 01:05 TomOnTime

@TomOnTime then we are back here:

+ set -e
+ . _blackbox_common.sh
++ exec /usr/local/Cellar/blackbox/1.20160122/libexec/_blackbox_common.sh

evanccnyc avatar May 18 '16 15:05 evanccnyc

The code has been improved a lot in this area. "make test" should handle this case now. Please take a look and let me know.

tlimoncelli avatar May 29 '17 23:05 tlimoncelli