Skip to content

Commit

Permalink
Resolve "delete-file before update-index" conundrum
Browse files Browse the repository at this point in the history
1. Move the files, to ensure permissions are correct
2. Update index

3a. If Update index success: Remove files
3b. If Update index failure: Restore files

Signed-off-by: Richard T Bonhomme <[email protected]>
  • Loading branch information
TinCanTech committed Feb 8, 2022
1 parent d07f430 commit 1add248
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions easytls
Original file line number Diff line number Diff line change
Expand Up @@ -2944,16 +2944,37 @@ remove_inline ()
[ -f "${inline_file}-badhash" ] && \
die "File exists: ${inline_file}-badhash"

# Move
if [ -z "${force_remove}" ]; then
"${EASYTLS_RM}" "${inline_file}" || \
"${EASYTLS_MV}" "${inline_file}" "${inline_file}-deleteme" || \
die "Failed to remove: ${inline_file}"
else
"${EASYTLS_MV}" "${inline_file}" "${inline_file}-badhash" || \
die "Failed to rename: ${inline_file}"
fi

# Update the index first
inline_index_update del || die "Failed to update inline-index"
if inline_index_update del; then
# Remove
if [ -z "${force_remove}" ]; then
"${EASYTLS_RM}" "${inline_file}-deleteme" || \
die "Failed to remove: ${inline_file}"
else
"${EASYTLS_RM}" "${inline_file}" || \
die "Failed to rename: ${inline_file}"
fi
else
# Undo move
if [ -z "${force_remove}" ]; then
"${EASYTLS_MV}" "${inline_file}-deleteme" "${inline_file}" || \
die "Failed to restore: ${inline_file}"
else
"${EASYTLS_MV}" "${inline_file}-badhash" "${inline_file}" || \
die "Failed to restore: ${inline_file}"
fi
# Always die
die "Failed to update inline-index"
fi

# Inline file and record deleted - Forget the HASH
# Otherwise 'inline_renew add' still has the HASH
Expand Down

1 comment on commit 1add248

@TinCanTech
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.