Skip to content

Instantly share code, notes, and snippets.

@mrkskwsnck
Created August 21, 2022 16:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrkskwsnck/81d5d24945def32e871a8fc02d146359 to your computer and use it in GitHub Desktop.
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.
#!/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