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 5ac08e37d8ad58cfc2e18ba1b92269660bb653c8
parent d446d3889bcf43437a930409ed91c6a56c865d38
Author: Natasha Kerensikova <natgh@instinctive.eu>
Date:   Sun, 15 Sep 2024 15:44:31 +0000

Target directory is no longer created before moving a directory

`mv src/ dest/` is a renaming only when `dest/` does not exist,
otherwise it moves `src/` into `dest/` instead of renaming.
Diffstat:
Mspec/action_spec.sh | 5++---
Msrc/pashage.sh | 5+++--
2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/spec/action_spec.sh b/spec/action_spec.sh @@ -201,7 +201,6 @@ Describe 'Action Functions' It 'moves a whole directory with identity' result() { %text:expand - #|$ mkdir -p -- ${PREFIX}/subdir/sub/ #|$ scm_begin #|$ scm_mv sub/ subdir/sub/ #|$ scm_commit Move sub/ to subdir/sub/ @@ -214,8 +213,8 @@ Describe 'Action Functions' It 'recursively re-enecrypts a directory' result() { %text:expand - #|$ mkdir -p -- ${PREFIX}/subdir/new-bare/ #|$ scm_begin + #|$ mkdir -p -- ${PREFIX}/subdir/new-bare #|$ do_decrypt ${PREFIX}/sub/bare/deep.age #|$ do_encrypt subdir/new-bare/deep.age #|$ scm_rm sub/bare/deep.age @@ -244,8 +243,8 @@ Describe 'Action Functions' } result() { %text:expand - #|$ mkdir -p -- ${PREFIX}/subdir/new-bare/ #|$ scm_begin + #|$ mkdir -p -- ${PREFIX}/subdir/new-bare #|$ yesno Reencrypt sub/bare/deep into subdir/new-bare/deep? #|$ scm_cp sub/bare/deep.age subdir/new-bare/deep.age #|$ mkdir -p -- ${PREFIX}/subdir/new-bare/sub diff --git a/src/pashage.sh b/src/pashage.sh @@ -247,7 +247,6 @@ do_copy_move() { die "Error: ${DEST%/} is not a directory" fi fi - mkdir -p -- "${PREFIX}/${DEST}" elif [ "$2" = "${2%/}/" ]; then mkdir -p -- "${PREFIX}/$2" @@ -337,6 +336,7 @@ do_copy_move() { do_copy_move_dir() { [ "$1" = "${1%/}/" ] || [ -z "$1" ] || die 'Internal error' [ "$2" = "${2%/}/" ] || [ -z "$2" ] || die 'Internal error' + [ -d "${PREFIX}/$1" ] || die 'Internal error' if [ -e "${PREFIX}/$1.age-recipients" ] \ && { [ "${DECISION}" = keep ] || [ "${DECISION}" = default ]; } @@ -344,6 +344,8 @@ do_copy_move_dir() { # Recipiends are transported too, no need to reencrypt "${SCM_ACTION}" "$1" "$2" else + [ -d "${PREFIX}/$2" ] || mkdir -p -- "${PREFIX}/${2%/}" + for ARG in "${PREFIX}/$1".* "${PREFIX}/$1"*; do SRC="${ARG#"${PREFIX}/"}" DEST="$2$(basename "${ARG}")" @@ -352,7 +354,6 @@ do_copy_move_dir() { do_copy_move_file "${SRC}" "${DEST}" elif [ -d "${ARG}" ] && [ "${ARG}" = "${ARG%/.*}" ] then - mkdir -p -- "${PREFIX}/${DEST}" do_copy_move_dir "${SRC}/" "${DEST}/" fi done