Skip to content

Commit

Permalink
feat: do not decrypt if the text file is newer than the encrypted file
Browse files Browse the repository at this point in the history
This implies that the user may have changed the text file sometime
after they created the encrypted copy. So we do not decrypt the older
encrypted file---this would overwrite the text file.
  • Loading branch information
sanjayankur31 committed May 6, 2022
1 parent f9a0bb5 commit 3d4a95c
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions calliope.sh
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,13 @@ decrypt ()
then
echo "Decrypting $1 with $encryptionId"
nongpgfname="$(basename $1 .gpg)"
$GPG_COMMAND --batch --yes --decrypt $1 > "$nongpgfname"

if [ "$1" -nt "$nongpgfname" ]
then
$GPG_COMMAND --batch --yes --decrypt $1 > "$nongpgfname"
else
echo "WARNING: Decrypted file is newer than encrypted copy."
echo "WARNING: Not overwriting. Please check the files, and re-encrypt if required."
fi
else
echo "File is not a GPG encrypted file. Doing nothing."
fi
Expand Down

0 comments on commit 3d4a95c

Please sign in to comment.