Fixed two issues: handle spaces in paths, and don't copy assets.external into .lowres tree

master
Taha Ahmed 4 years ago
parent e467fb74df
commit 0534288dcc

@ -144,12 +144,15 @@ if [ $# -eq 1 ]; then
# if $asset contains a space, the second element should be considered a local target folder for the copy operation # if $asset contains a space, the second element should be considered a local target folder for the copy operation
# https://www.tutorialkart.com/bash-shell-scripting/bash-split-string/ # https://www.tutorialkart.com/bash-shell-scripting/bash-split-string/
# https://stackoverflow.com/a/30212526 # https://stackoverflow.com/a/30212526
IFS=' ' # reset IFS # Using space as separator was not working if the path contains spaces
# (I tried surrounding each path with "" or escaping each space with backslash, did not help)
# Rather than rewriting this part, I'll change to an IFS char that's unlikely to clash with any path specification. This way, spaces in paths should not need any changes.
IFS='>' # reset IFS
# asset is read into an array as tokens separated by IFS # asset is read into an array as tokens separated by IFS
read -ra asset_array <<< "$asset" read -ra asset_array <<< "$asset"
# sanity check for array length # sanity check for array length
if [ ${#asset_array[@]} -gt 2 ]; then if [ ${#asset_array[@]} -gt 2 ]; then
echo "<thesis> Cannot handle more than one space per line" echo "<thesis> Cannot handle more than one $IFS character per line"
echo "<cheRTeX> Terminating..." echo "<cheRTeX> Terminating..."
simpledelay.sh 2 simpledelay.sh 2
exit 1 exit 1
@ -189,15 +192,16 @@ if [ $# -eq 1 ]; then
photoslastrun="$path_thesis/assets/photos/.lowres/lastrun" photoslastrun="$path_thesis/assets/photos/.lowres/lastrun"
if [ ! -f "$photoslastrun" ]; then if [ ! -f "$photoslastrun" ]; then
# if, for some reason, the lastrun file does not exist # if, for some reason, the lastrun file does not exist
# copy over everything and then create the file # copy over everything and then create the file
rsync -av "$path_thesis/assets/photos/" "$path_thesis/assets/photos/.lowres/" --exclude ".lowres/" # (except for the .lowres tree itself, and any assets.external files)
rsync -av "$path_thesis/assets/photos/" "$path_thesis/assets/photos/.lowres/" --exclude ".lowres/" --exclude "assets.external"
touch "$photoslastrun" touch "$photoslastrun"
fi fi
# Detect new photos and copy them into .lowres tree # Detect new photos and copy them into .lowres tree
# https://stackoverflow.com/questions/9612090/how-to-loop-through-file-names-returned-by-find # https://stackoverflow.com/questions/9612090/how-to-loop-through-file-names-returned-by-find
# https://stackoverflow.com/questions/5241625/find-and-copy-files # https://stackoverflow.com/questions/5241625/find-and-copy-files
cd "$path_thesis/assets/photos" cd "$path_thesis/assets/photos"
find . -type f -cnewer $photoslastrun ! -path "./.lowres/*" -print -exec cp --parents "{}" .lowres \; find . -type f -cnewer $photoslastrun ! -path "./.lowres/*" ! -name "*.external" -print -exec cp --parents "{}" .lowres \;
# revert the effects of cd above. Redirect to null suppresses the output. # revert the effects of cd above. Redirect to null suppresses the output.
cd - >/dev/null cd - >/dev/null
# Convert all non-JPG images (except for PDF, SVG, and other non-images) to JPG # Convert all non-JPG images (except for PDF, SVG, and other non-images) to JPG

Loading…
Cancel
Save