Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix how vcs_relative_path first resolves an absolute path #305

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 14 additions & 5 deletions bin/_blackbox_common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -366,13 +366,22 @@ function enumerate_blackbox_repos() {
done
}

# Resolve the absolute path of a relative one
# Adapted from https://unix.stackexchange.com/a/483514
function abs() {
local _pwd bn
[ -d "${1}" ] && _pwd="${1}"
[ -f "${1}" ] && { _pwd=$(dirname "${1}") ; bn=/$(basename "${1}") ;}
pushd "$_pwd" >/dev/null || exit
echo "$(pwd)${bn}"
popd >/dev/null || exit
}

# Output the path of a file relative to the repo base
function vcs_relative_path() {
# Usage: vcs_relative_path file
local name="$1"
#python -c 'import os ; print(os.path.relpath("'"$(pwd -P)"'/'"$name"'", "'"$REPOBASE"'"))'
local p=$( printf "%s" "$( pwd -P )/${1}" | sed 's#//*#/#g' )
local name="${p#$REPOBASE}"
local name
name=$(abs "$1")
name="${name#$REPOBASE}"
name=$( printf "%s" "$name" | sed 's#^/##g' | sed 's#/$##g' )
printf "%s" "$name"
}
Expand Down
2 changes: 1 addition & 1 deletion bin/blackbox_register_new_file
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ function register_new_file() {
prepare_keychain
encrypt_file "$unencrypted_file" "$encrypted_file"
add_filename_to_cryptlist "$unencrypted_file"
vcs_ignore "$unencrypted_file"

# Is the unencrypted file already in HG? (ie. are we correcting a bad situation)
SECRETSEXPOSED=$(is_in_vcs "${unencrypted_file}")
Expand All @@ -41,7 +42,6 @@ function register_new_file() {
vcs_add "$encrypted_file"
fi

vcs_ignore "$unencrypted_file"
echo 'NOTE: "already tracked!" messages are safe to ignore.'
vcs_add "$BB_FILES" "$encrypted_file"
vcs_commit "registered in blackbox: ${unencrypted_file}" "$BB_FILES" "$encrypted_file" "$(vcs_ignore_file_path)"
Expand Down
6 changes: 6 additions & 0 deletions tools/confidence_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,12 @@ blackbox_register_new_file secret.txt
assert_file_missing secret.txt
assert_file_exists secret.txt.gpg
assert_line_exists '/secret.txt' .gitignore
assert_line_exists 'secret.txt' keyrings/live/blackbox-files.txt

PHASE 'She cats secrets.txt.gpg.'
make_self_deleting_tempfile catsecret
blackbox_cat secret.txt.gpg > $catsecret
assert_line_exists 'this is my secret' $catsecret

PHASE 'She decrypts secrets.txt.'
blackbox_edit_start secret.txt
Expand Down