pashage

Yet Another Opinionated Re-engineering of the Unix Password Store
git clone https://git.instinctive.eu/pashage.git
Log | Files | Refs | README | LICENSE

commit 62f0ea5ad633e7d31a1c2e2b188e2b4bc5953089
parent 14e86989129d033605b95d2e05d82bfef58c2fc3
Author: Natasha Kerensikova <natgh@instinctive.eu>
Date:   Sat,  9 Nov 2024 08:05:16 +0000

Changes by do_reencrypt are committed
Diffstat:
Mspec/action_spec.sh | 24++++++++++++++++++++----
Msrc/pashage.sh | 8++++++++
2 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/spec/action_spec.sh b/spec/action_spec.sh @@ -1612,6 +1612,8 @@ Describe 'Action Functions' mktemp() { %putsn "$1"; } mv() { mocklog mv "$@"; } scm_add() { mocklog scm_add "$@"; } + scm_begin() { mocklog scm_begin "$@"; } + scm_commit() { mocklog scm_commit "$@"; } setup() { @mkdir -p "${PREFIX}/subdir/subsub" @@ -1630,10 +1632,12 @@ Describe 'Action Functions' It 're-encrypts a single file' result() { %text:expand + #|$ scm_begin #|$ do_decrypt ${PREFIX}/subdir/subsub/deep.age #|$ do_encrypt subdir/subsub/deep-XXXXXXXXX.age #|$ mv -f -- ${PREFIX}/subdir/subsub/deep-XXXXXXXXX.age ${PREFIX}/subdir/subsub/deep.age #|$ scm_add subdir/subsub/deep.age + #|$ scm_commit Re-encrypt subdir/subsub/deep } When call do_reencrypt subdir/subsub/deep The status should be success @@ -1644,6 +1648,7 @@ Describe 'Action Functions' It 'recursively re-encrypts a directory' result() { %text:expand + #|$ scm_begin #|$ do_decrypt ${PREFIX}/subdir/middle.age #|$ do_encrypt subdir/middle-XXXXXXXXX.age #|$ mv -f -- ${PREFIX}/subdir/middle-XXXXXXXXX.age ${PREFIX}/subdir/middle.age @@ -1652,6 +1657,7 @@ Describe 'Action Functions' #|$ do_encrypt subdir/subsub/deep-XXXXXXXXX.age #|$ mv -f -- ${PREFIX}/subdir/subsub/deep-XXXXXXXXX.age ${PREFIX}/subdir/subsub/deep.age #|$ scm_add subdir/subsub/deep.age + #|$ scm_commit Re-encrypt subdir/ } When call do_reencrypt subdir/ The status should be success @@ -1669,12 +1675,14 @@ Describe 'Action Functions' } result() { %text:expand + #|$ scm_begin #|$ yesno Re-encrypt subdir/middle? #|$ yesno Re-encrypt subdir/subsub/deep? #|$ do_decrypt ${PREFIX}/subdir/subsub/deep.age #|$ do_encrypt subdir/subsub/deep-XXXXXXXXX.age #|$ mv -f -- ${PREFIX}/subdir/subsub/deep-XXXXXXXXX.age ${PREFIX}/subdir/subsub/deep.age #|$ scm_add subdir/subsub/deep.age + #|$ scm_commit Re-encrypt subdir/ } When call do_reencrypt subdir The status should be success @@ -1683,18 +1691,26 @@ Describe 'Action Functions' End It 'reports a non-existent directory' + result() { + %text + #|$ scm_begin + #|Error: non-existent/ is not in the password store. + } When run do_reencrypt non-existent/ The output should be blank - The error should equal \ - 'Error: non-existent/ is not in the password store.' + The error should equal "$(result)" The status should equal 1 End It 'reports a non-existent file' + result() { + %text + #|$ scm_begin + #|Error: non-existent is not in the password store. + } When run do_reencrypt non-existent The output should be blank - The error should equal \ - 'Error: non-existent is not in the password store.' + The error should equal "$(result)" The status should equal 1 End End diff --git a/src/pashage.sh b/src/pashage.sh @@ -818,21 +818,29 @@ do_list_or_show() { # $1: entry name # DECISION: whether to ask before re-encryption do_reencrypt() { + scm_begin + if [ "$1" = "${1%/}/" ]; then if ! [ -d "${PREFIX}/${1%/}" ]; then die "Error: $1 is not in the password store." fi do_reencrypt_dir "${PREFIX}/${1%/}" + LOC="$1" elif [ -f "${PREFIX}/$1.age" ]; then do_reencrypt_file "$1" + LOC="$1" elif [ -d "${PREFIX}/$1" ]; then do_reencrypt_dir "${PREFIX}/$1" + LOC="$1/" else die "Error: $1 is not in the password store." fi + + scm_commit "Re-encrypt ${LOC}" + unset LOC } # Recursively re-encrypts a directory