Replaced a couple of xargs instances with while read loops,

and added log commands directly to find commands rather than
writing to and reading from temporary log files during dry run.
This commit is contained in:
koroshiya 2015-11-10 09:06:18 +11:00
parent 7c9e85b6e2
commit 4b43fd4fb1
1 changed files with 6 additions and 7 deletions

View File

@ -1752,13 +1752,12 @@ function _SoftDeleteLocal {
fi fi
if [ $_VERBOSE -eq 1 ]; then if [ $_VERBOSE -eq 1 ]; then
# Cannot launch log function from xargs, ugly hack # Cannot launch log function from xargs, ugly hack
$FIND_CMD "$replica_deletion_path/" -type f -mtime +$change_time -print0 | xargs -0 -I {} echo "Will delete file {}" > "$RUN_DIR/osync.$FUNCNAME.$SCRIPT_PID" $FIND_CMD "$replica_deletion_path/" -type f -mtime +$change_time -print0 | while read filename; do Logger "Command output:\nWill delete file $filename" "NOTICE"; done
Logger "Command output:\n$(cat $RUN_DIR/osync.$FUNCNAME.$SCRIPT_PID)" "NOTICE" $FIND_CMD "$replica_deletion_path/" -type d -empty -mtime +$change_time -print0 | while read filename; do Logger "Command output:\nWill delete directory $filename" "NOTICE"; done
$FIND_CMD "$replica_deletion_path/" -type d -empty -mtime +$change_time -print0 | xargs -0 -I {} echo "Will delete directory {}" > "$RUN_DIR/osync.$FUNCNAME.$SCRIPT_PID"
Logger "Command output:\n$(cat $RUN_DIR/osync.$FUNCNAME.$SCRIPT_PID)" "NOTICE"
fi fi
if [ $_DRYRUN -ne 1 ]; then if [ $_DRYRUN -ne 1 ]; then
$FIND_CMD "$replica_deletion_path/" -type f -mtime +$change_time -print0 | xargs -0 -I {} rm -f "{}" && $FIND_CMD "$replica_deletion_path/" -type d -empty -mtime +$change_time -print0 | xargs -0 -I {} rm -rf "{}" > "$RUN_DIR/osync.$FUNCNAME.$SCRIPT_PID" 2>&1 & $FIND_CMD "$replica_deletion_path/" -type f -mtime +$change_time -print0 | while read filename; do rm -f "$filename" > "$RUN_DIR/osync.$FUNCNAME.$SCRIPT_PID" 2>&1 &; done
$FIND_CMD "$replica_deletion_path/" -type d -empty -mtime +$change_time -print0 | while read filename; do rm -rf "$filename" > "$RUN_DIR/osync.$FUNCNAME.$SCRIPT_PID" 2>&1 &; done
else else
Dummy & Dummy &
fi fi