Skip to content

Commit 462b551

Browse files
committed
some updates for Clean moved empty folders
Signed-off-by: DaRK AnGeL <[email protected]>
1 parent b2eed29 commit 462b551

File tree

1 file changed

+18
-10
lines changed
  • source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning

1 file changed

+18
-10
lines changed

source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1648,7 +1648,7 @@ processTheMoves() {
16481648
REMAINING_UNATTENDED_FOLDERS=$TOTALUNATTENDEDFOLDERS
16491649

16501650
# Dry mode info:
1651-
if [ $TESTMODE = "yes" ]; then
1651+
if [ "$TESTMODE" = "yes" ]; then
16521652
mvlogger "Warning: Test Mode: yes, running $MOVE_FILES_TOOL in dry-mode for moving $([ "$MOVE_FILES_TOOL" = "rsync" ] && echo 'and syncing')"
16531653
fi
16541654

@@ -1876,20 +1876,28 @@ processTheMoves() {
18761876

18771877
# Clean moved empty folders
18781878
if [[ "$ACTION" =~ "move" && "$FILETYPE" == "d" ]]; then
1879-
if [ -d "${SOURCE}/${FILEPATH}" ]; then
1880-
DIR="${SOURCE}/${FILEPATH}"
1881-
mvDebuglogger "Current folder: $FILEPATH" "Clean Empty Moved Folder - Start Loop"
1879+
DIR="${SOURCE}/${FILEPATH}"
1880+
1881+
if [ -d "$DIR" ]; then
1882+
mvDebuglogger "Current folder: $DIR" "Clean Empty Moved Folder - Start Loop"
18821883

18831884
if [ -e "${DIR}/.placeholder" ]; then
1884-
fodler_file_count=0 # Assume no files if .placeholder exists
1885+
file_count=".placeholder"
18851886
else
1886-
fodler_file_count=$(find "${DIR}" -type f | wc -l)
1887+
file_count=$(find "$DIR" -type f | wc -l)
18871888
fi
1889+
# Count subdirectories
1890+
dir_count=$(find "$DIR" -mindepth 1 -type d | wc -l)
18881891

1889-
if [ "$fodler_file_count" -eq 0 ] && [ "$TESTMODE" = "no" ]; then
1890-
mvlogger "Deleting empty folder: ${DIR}"
1891-
# Check if empty folder exists and remove it
1892-
[ -d "${DIR}" ] && rmdir "${DIR}"
1892+
if [ "$file_count" -eq 0 ] && [ "$dir_count" -eq 0 ] && [ "$file_count" != ".placeholder" ]; then
1893+
if [ "$TESTMODE" = "no" ]; then
1894+
mvlogger "Deleting moved empty folder: ${DIR}"
1895+
rmdir "$DIR"
1896+
else
1897+
mvlogger "TEST MODE: Would delete moved empty folder: ${DIR}"
1898+
fi
1899+
else
1900+
mvlogger "Not deleting folder: contains $file_count file(s), $dir_count subfolder(s): $DIR"
18931901
fi
18941902
fi
18951903
fi

0 commit comments

Comments
 (0)