Просмотр исходного кода

Better handle filename encoding mismatches

Zachary Kotlarek 12 лет назад
Родитель
Сommit
4fa3b61299
2 измененных файлов с 24 добавлено и 1 удалено
  1. 14 1
      sync/sync.sh
  2. 10 0
      sync/syncUnwatched.sh

+ 14 - 1
sync/sync.sh

@@ -98,5 +98,18 @@ for infile in $FILES; do
 	fi
 
 	# Encode things that do not
-	~/bin/video/encode.pl "${IN_DIR}/${infile}"
+	ERR="`~/bin/video/encode.pl "${IN_DIR}/${infile}" 2>&1`"
+
+	# If the singular output error is "already exists" assume the error is related to filename encoding
+	# Suppress the error and touch the output file to prevent it from being deleted
+	if [ -n "${ERR}" ] && \
+		[ `echo "${ERR}" | wc -l` -eq 1 ] && \
+		echo "${ERR}" | grep -q 'encode.pl: Output file exists: '; then
+			OUTFILE="`echo "${ERR}" | \
+				sed 's%encode.pl: Output file exists: %%' | \
+				sed 's%. Skipping...%%'`"
+			touch "${OUTFILE}"
+	else
+		echo "${ERR}" 1>&2
+	fi
 done

+ 10 - 0
sync/syncUnwatched.sh

@@ -90,7 +90,17 @@ done
 
 # Delete anything leftover
 IFS=$'\n'
+MIN_AGE="`date -v -1H +%s`"
 for i in $OLD_FILES; do
+	# Skip files under 1H old to avoid churn and provide a no-delete signal for other conditions (e.g. filename encoding)
+	if [ `stat -f '%m' "${BASE_DIR}/${i}"` -ge $MIN_AGE ]; then
+		if [ $DEBUG -gt 0 ]; then
+			echo "Will skip due to minimum age: ${BASE_DIR}/${i}"
+		fi
+		continue
+	fi
+
+	# Delete if set to sync
 	if [ $DEBUG -gt 0 ]; then
 		echo "Will delete: ${BASE_DIR}/${i}"
 	fi