Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sh format: improve stampfile handling #556

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 25 additions & 6 deletions lib/formats/sh.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ DO_KEEP_DIR_TIMESTAMPS=
# Set to true on -i
DO_ASK_BEFORE_DELETE=

# Tempfiles for saving timestamps
STAMPFILE=
STAMPFILE2=

##################################
# GENERAL LINT HANDLER FUNCTIONS #
##################################
Expand All @@ -51,6 +55,19 @@ COL_GREEN='\e[0;32m'
COL_YELLOW='\e[0;33m'
COL_RESET='\e[0m'

exit_cleanup() {
trap - INT TERM EXIT
if [ -n "$STAMPFILE" ]; then
rm -f -- "$STAMPFILE"
fi
if [ -n "$STAMPFILE2" ]; then
rm -f -- "$STAMPFILE2"
fi
}

trap exit_cleanup EXIT
trap exit INT TERM

print_progress_prefix() {
if [ -n "$DO_SHOW_PROGRESS" ]; then
PROGRESS_PERC=0
Expand Down Expand Up @@ -218,12 +235,15 @@ cp_reflink() {
printf "${COL_YELLOW}Reflinking to original: ${COL_RESET}%%s\n" "$1"
if original_check "$1" "$2"; then
if [ -z "$DO_DRY_RUN" ]; then
touch -mr "$1" -- "$0"
if [ -z "$STAMPFILE2" ]; then
STAMPFILE2=$(mktemp "${TMPDIR:-/tmp}/rmlint.XXXXXXXX.stamp")
fi
touch -mr "$1" -- "$STAMPFILE2"
if [ -d "$1" ]; then
rm -rf -- "$1"
fi
cp --archive --reflink=always -- "$2" "$1"
touch -mr "$0" -- "$1"
touch -mr "$STAMPFILE2" -- "$1"
fi
fi
}
Expand Down Expand Up @@ -278,7 +298,6 @@ remove_cmd() {
if [ -n "$DO_KEEP_DIR_TIMESTAMPS" ]; then
# Swap back old directory timestamp:
touch -r "$STAMPFILE" -- "$(dirname "$1")"
rm -- "$STAMPFILE"
fi

if [ -n "$DO_DELETE_EMPTY_DIRS" ]; then
Expand Down Expand Up @@ -380,7 +399,6 @@ do
;;
k)
DO_KEEP_DIR_TIMESTAMPS=true
STAMPFILE=$(mktemp 'rmlint.XXXXXXXX.stamp')
;;
i)
DO_ASK_BEFORE_DELETE=true
Expand All @@ -402,11 +420,12 @@ then
ask
fi

if [ -n "$DO_DRY_RUN" ]
then
if [ -n "$DO_DRY_RUN" ]; then
printf "#${COL_YELLOW} ////////////////////////////////////////////////////////////${COL_RESET}\n"
printf "#${COL_YELLOW} /// ${COL_RESET} This is only a dry run; nothing will be modified! ${COL_YELLOW}///${COL_RESET}\n"
printf "#${COL_YELLOW} ////////////////////////////////////////////////////////////${COL_RESET}\n"
elif [ -n "$DO_KEEP_DIR_TIMESTAMPS" ]; then
STAMPFILE=$(mktemp "${TMPDIR:-/tmp}/rmlint.XXXXXXXX.stamp")
fi

######### START OF AUTOGENERATED OUTPUT #########
Expand Down