Skip to content

Commit f904f80

Browse files
axdjuraevlukrop
authored andcommitted
Enhance cmd_store() function with improved file handling and encryption logic
This commit improves the cmd_store() function by addressing relative path issues, enhancing absolute file path handling, and ensuring robust checks for file existence before proceeding with encryption and storage.
1 parent 3f40aac commit f904f80

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

file.bash

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@ cmd_store() {
2020
local passfile="$PREFIX/$path.gpg"
2121

2222
cd $OLDPWD # fix for relative paths
23+
local file_abs_path="$OLDPWD/$file"
2324

2425
check_sneaky_paths "$1"
2526
set_git "$passfile"
2627

27-
if [[ -z $path || -z $file ]]; then
28+
if [[ -z $path || -z "$file_abs_path" ]]; then
2829
print_usage
29-
elif [[ ! -f $file ]]; then
30+
elif [[ ! -f "$file_abs_path" ]]; then
3031
die "Error: $file does not exist."
3132
fi
3233

@@ -41,7 +42,7 @@ cmd_store() {
4142

4243
set_gpg_recipients "$(dirname "$path")"
4344

44-
base64 $file | $GPG -e "${GPG_RECIPIENT_ARGS[@]}" -o "$passfile" "${GPG_OPTS[@]}"
45+
base64 $file_abs_path | $GPG -e "${GPG_RECIPIENT_ARGS[@]}" -o "$passfile" "${GPG_OPTS[@]}"
4546

4647
git_add_file $passfile "Store arbitary file for $path to store."
4748
}
@@ -126,4 +127,3 @@ case $1 in
126127
print_usage
127128
;;
128129
esac
129-

0 commit comments

Comments
 (0)