commit f562e3cda4f5407ef8fa8f969cad7cc1a92f3f89
parent 1694b56b9bf123e252de6171a5496e05a62b4b11
Author: Natasha Kerensikova <natgh@instinctive.eu>
Date: Sun, 3 Nov 2024 12:04:43 +0000
Pre-checks of destination directories in copy and move command is streamlined
Diffstat:
2 files changed, 8 insertions(+), 19 deletions(-)
diff --git a/spec/action_spec.sh b/spec/action_spec.sh
@@ -91,7 +91,6 @@ Describe 'Action Functions'
SCM_ACTION=scm_cp
result() {
%text:expand
- #|$ mkdir -p -- ${PREFIX}/sub/
#|$ scm_begin
#|$ do_decrypt ${PREFIX}/root.age
#|$ do_encrypt sub/root.age
@@ -126,9 +125,7 @@ Describe 'Action Functions'
DECISION=keep
ACTION=Copy
SCM_ACTION=scm_cp
- result() {
- %text:expand
- #|$ mkdir -p -- ${PREFIX}/sub/
+ result() { %text
#|$ scm_begin
#|$ scm_cp root.age sub/root.age
#|$ scm_commit Copy root.age to sub/root.age
@@ -140,9 +137,7 @@ Describe 'Action Functions'
End
It 'does not re-encrypt a non-encrypted file'
- result() {
- %text:expand
- #|$ mkdir -p -- ${PREFIX}/sub/
+ result() { %text
#|$ scm_begin
#|$ scm_mv notes.txt sub/notes.txt
#|$ scm_commit Move notes.txt to sub/notes.txt
@@ -155,9 +150,7 @@ Describe 'Action Functions'
It 'does not re-encrypt a non-encrypted file even when forced'
DECISION=force
- result() {
- %text:expand
- #|$ mkdir -p -- ${PREFIX}/sub/
+ result() { %text
#|$ scm_begin
#|$ scm_mv notes.txt sub/notes.txt
#|$ scm_commit Move notes.txt to sub/notes.txt
@@ -169,8 +162,7 @@ Describe 'Action Functions'
End
It 'moves a file without re-encrypting to another directory'
- result() {
- %text:expand
+ result() { %text
#|$ scm_begin
#|$ scm_mv sub/secret.age subdir/secret.age
#|$ scm_commit Move sub/secret.age to subdir/secret.age
@@ -301,7 +293,7 @@ Describe 'Action Functions'
It 'cannot overwrite a directory with a file'
When run do_copy_move notes.txt subdir
The output should be blank
- The error should equal 'Error: subdir already contains notes.txt'
+ The error should equal 'Error: subdir already contains notes.txt/'
The status should equal 1
End
diff --git a/src/pashage.sh b/src/pashage.sh
@@ -250,16 +250,13 @@ do_copy_move() {
fi
fi
- elif [ "$2" = "${2%/}/" ]; then
- mkdir -p -- "${PREFIX}/$2"
+ elif [ "$2" = "${2%/}/" ] || [ -d "${PREFIX}/$2" ]; then
+ [ -d "${PREFIX}/$2" ] || mkdir -p -- "${PREFIX}/$2"
[ -d "${PREFIX}/$2" ] || die "Error: $2 is not a directory"
- DEST="$2$(basename "${SRC}")"
- LOCAL_ACTION=do_copy_move_file
- elif [ -d "${PREFIX}/$2" ]; then
DEST="${2%/}/$(basename "${SRC}")"
if [ -d "${PREFIX}/${DEST}" ]; then
- die "Error: $2 already contains $(basename "${SRC}")"
+ die "Error: $2 already contains $(basename "${SRC}")/"
fi
LOCAL_ACTION=do_copy_move_file