diff --git a/Dockerfile b/Dockerfile index dc906b9..e6b02cf 100644 --- a/Dockerfile +++ b/Dockerfile @@ -36,7 +36,9 @@ RUN sed -i 's///dev/null; then + log "Skipping file '$file': currently being accessed." + # Invalidate the watch directory hash. If we don't, we may never + # process this file because the hash may remain the same. + WATCHDIR_HASH_invalidate + return + fi + + # Get hash of the file from its name, size and time. hash="$(stat -c '%n %s %Y' "$file" | md5sum | cut -d' ' -f1)" + + # Skip file if it has been already successfully processed. if grep -q -w "$hash" "$SUCCESSFUL_CONVERSIONS"; then log "Skipping file '$file' ($hash): already processed successfully." - continue + return fi + + # Skip file if we already failed to process it. if grep -q -w "$hash" "$FAILED_CONVERSIONS"; then log "Skipping file '$file' ($hash): already processed with failure." - continue + return fi log "Starting conversion of '$file' ($hash)..." @@ -53,23 +93,21 @@ echo "Starting watchfolder service..." [ -f "$FAILED_CONVERSIONS" ] || touch "$FAILED_CONVERSIONS" [ -f "$SUCCESSFUL_CONVERSIONS" ] || touch "$SUCCESSFUL_CONVERSIONS" -DIRHASH=UNSET while true; do - PREHASH="$(watchdir_hash)" - if [ "$DIRHASH" != "$PREHASH" ]; then - if [ "$DIRHASH" != "UNSET" ]; then + if WATCHDIR_HASH_changed; then + if WATCHDIR_HASH_isset; then log "Watch folder: New file(s) detected!" fi + # Make sure to update the watch directory hash before processing it. + # This is to make sure we catch, on the next round, changes occuring + # during the processing. + WATCHDIR_HASH_update log "Processing watch folder..." find /watch -follow -maxdepth 1 -type f | while read FILE do process_file "$FILE" done - log "Watch folder processing terminated" - POSTHASH="$(watchdir_hash)" - if [ "$DIRHASH" == "UNSET" ] || [ "$PREHASH" == "$POSTHASH" ]; then - DIRHASH="$PREHASH" - fi + log "Watch folder processing terminated." fi sleep 5