Created
August 21, 2022 16:28
-
-
Save mrkskwsnck/81d5d24945def32e871a8fc02d146359 to your computer and use it in GitHub Desktop.
Search synchronized files conflicted by Nextcloud and replace the original file if it is zero sized.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/bash | |
# Search synchronized files conflicted by Nextcloud and | |
# replace the original file if it is zero sized. | |
START_DIR="$1" | |
GLOB_PATTERN=' (conflicted copy ????-??-?? *)' | |
REGEX_PATTERN=' \(conflicted copy [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]+\)' | |
OLDIFS=$IFS | |
IFS=$'\n' | |
for CONFLICTED_PATH in $(find "${START_DIR:-.}" -name "*${GLOB_PATTERN}*") | |
do | |
ZERO_PATH=$(echo "$CONFLICTED_PATH" | sed --regexp-extended "s/$REGEX_PATTERN//") | |
# Original file does not exist or is zero sized | |
if [ ! -s "$ZERO_PATH" ] | |
then | |
echo -n "Renaming '$CONFLICTED_PATH' to '$ZERO_PATH' ..." | |
mv "$CONFLICTED_PATH" "$ZERO_PATH" | |
echo ' done.' | |
fi | |
done | |
IFS=$OLDIFS |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment