From 1340e329768f8f022c6d5cd91e512380d883a5ac Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Thu, 14 Nov 2013 14:36:46 -0200 Subject: Set file extension for encrypted files --- lib/keyringer/actions/encrypt | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'lib/keyringer/actions/encrypt') diff --git a/lib/keyringer/actions/encrypt b/lib/keyringer/actions/encrypt index d9d8f96..aadb9fa 100755 --- a/lib/keyringer/actions/encrypt +++ b/lib/keyringer/actions/encrypt @@ -25,10 +25,25 @@ fi # Aditional parameters if [ ! -z "$3" ]; then - keyringer_get_new_file $2 + # Set secret name and original file + FILE="$2" shift 2 UNENCRYPTED_FILE="$*" + # Get original file EXTENSION + FILENAME="$(basename "$UNENCRYPTED_FILE")" + EXTENSION="${FILENAME##*.}" + + # Append file extension in the secret name + # + # Useful when opening files and the application needs the + # extension to guess the file type. + if ! echo $FILE | grep -q -e "\.$EXTENSION$"; then + FILE="$FILE.$EXTENSION" + fi + + keyringer_get_new_file $FILE + if [ ! -f "$UNENCRYPTED_FILE" ]; then echo "Error: cannot encrypt $UNENCRYPTED_FILE: file not found." exit 1 -- cgit v1.2.3