Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,14 @@ _(Move files tool)_:
<p><strong>Rsync</strong> - Use Rsync for both moving and syncing files.</p>
</blockquote>

: <select name='moveEmptyFolders' size='1' class='narrow'>
_(Move empty folders)_:
<?=mk_option($cfg['moveEmptyFolders'],"no",'No')?>
<?=mk_option($cfg['moveEmptyFolders'],"yes","Yes")?>
</select>

> This will also move <strong>empty folders</strong> in the share, including those that are not related to the files that were moved.

_(Clean empty folders)_:
: <select name='cleanFolders' size='1' class='narrow'>
<?=mk_option($cfg['cleanFolders'],"no",'No')?>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,17 @@ getMoverSettings() {
MOVE_FILES_TOOL=$(cfg movefilesTool)
mvlogger "Move files tool: $MOVE_FILES_TOOL"
fi

if [ -z $(cfg moveEmptyFolders) ]; then
if [[ ! "$config_file" =~ shareOverrideConfig ]]; then
mvlogger "No Move empty folders argument provided, defaulting to yes"
MOVE_EMPTY_FOLDERS="yes"
echo 'moveEmptyFolders="yes"' >>"$config_file"
fi
else
MOVE_EMPTY_FOLDERS=$(cfg moveEmptyFolders)
mvlogger "Move empty folders: $MOVE_EMPTY_FOLDERS"
fi
}

resetRunOnceMoverSettings() {
Expand Down Expand Up @@ -1067,8 +1078,12 @@ createFilteredFilelist() {
FINDSTR+=" \"${SHAREPATH}\""
fi

# Only search inside the share (skip the share root): files + empty dirs
FINDSTR+=" -mindepth 1 \( -type f -o -type d -empty \)"
if [[ "$MOVE_EMPTY_FOLDERS" == "yes" ]]; then
# Only search inside the share (skip the share root): files + empty dirs
FINDSTR+=" -mindepth 1 \( -type f -o -type d -empty \)"
else
FINDSTR+=" -type f"
fi

#Addition of filters are conditionned by [ -z "$OMOVERTHRESH" ] || [ $POOLPCTUSED -le $OMOVERTHRESH ] to prevent filtering move all Primary->Secondary share
# Add Age variables to find string
Expand Down Expand Up @@ -1648,7 +1663,7 @@ processTheMoves() {
REMAINING_UNATTENDED_FOLDERS=$TOTALUNATTENDEDFOLDERS

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

Expand Down Expand Up @@ -1874,6 +1889,34 @@ processTheMoves() {
fi
fi

# Clean moved empty folders
if [[ "$ACTION" =~ "move" && "$FILETYPE" == "d" ]] && [ "$MOVE_EMPTY_FOLDERS" = "yes" ]; then
DIR="${SOURCE}/${FILEPATH}"

if [ -d "$DIR" ]; then
mvDebuglogger "Current folder: $DIR" "Clean Empty Moved Folder - Start Loop"

if [ -e "${DIR}/.placeholder" ]; then
file_count=".placeholder"
else
file_count=$(find "$DIR" -type f | wc -l)
fi
# Count subdirectories
dir_count=$(find "$DIR" -mindepth 1 -type d | wc -l)

if [ "$file_count" != ".placeholder" ] && [ "$file_count" -eq 0 ] && [ "$dir_count" -eq 0 ]; then
if [ "$TESTMODE" = "no" ]; then
mvlogger "Deleting moved empty folder: ${DIR}"
rmdir "$DIR"
else
mvlogger "TEST MODE: Would delete moved empty folder: ${DIR}"
fi
else
mvlogger "Not deleting folder: contains $file_count file(s), $dir_count subfolder(s): $DIR"
fi
fi
fi

# Setting mover status
if [[ "$ACTION" =~ "unattended" ]]; then
REMAINING_UNATTENDED_SIZE=$((REMAINING_UNATTENDED_SIZE - FILESIZE))
Expand All @@ -1885,29 +1928,41 @@ processTheMoves() {
fi

if [[ "$ACTION" =~ "unattended to secondary" ]]; then
mvlogger "$REMAINING_UNATTENDED_FILES files remaining from unattended to secondary ($(bytes_to_human "$REMAINING_UNATTENDED_SIZE"))"
# Check if there are any files or folders left
if [[ "$FILETYPE" = "f" ]]; then
mvlogger "$REMAINING_UNATTENDED_FILES files remaining from unattended to secondary ($(bytes_to_human "$REMAINING_UNATTENDED_SIZE"))"
else
mvlogger "$REMAINING_UNATTENDED_FOLDERS folders remaining from unattended to secondary"
fi
elif [[ "$ACTION" =~ "unattended to primary" ]]; then
mvlogger "$REMAINING_UNATTENDED_FILES files remaining from unattended to primary ($(bytes_to_human "$REMAINING_UNATTENDED_SIZE"))"
# Check if there are any files or folders left
if [[ "$FILETYPE" = "f" ]]; then
mvlogger "$REMAINING_UNATTENDED_FILES files remaining from unattended to primary ($(bytes_to_human "$REMAINING_UNATTENDED_SIZE"))"
else
mvlogger "$REMAINING_UNATTENDED_FOLDERS folders remaining from unattended to primary"
fi
fi
Comment on lines 1930 to 1944

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This block of code contains duplicated logic for logging messages based on FILETYPE. This can be simplified by extracting the common parts and using a variable for the differing part (primary vs secondary), which improves maintainability and readability.

Suggested change
if [[ "$ACTION" =~ "unattended to secondary" ]]; then
mvlogger "$REMAINING_UNATTENDED_FILES files remaining from unattended to secondary ($(bytes_to_human "$REMAINING_UNATTENDED_SIZE"))"
# Check if there are any files or folders left
if [[ "$FILETYPE" = "f" ]]; then
mvlogger "$REMAINING_UNATTENDED_FILES files remaining from unattended to secondary ($(bytes_to_human "$REMAINING_UNATTENDED_SIZE"))"
else
mvlogger "$REMAINING_UNATTENDED_FOLDERS folders remaining from unattended to secondary"
fi
elif [[ "$ACTION" =~ "unattended to primary" ]]; then
mvlogger "$REMAINING_UNATTENDED_FILES files remaining from unattended to primary ($(bytes_to_human "$REMAINING_UNATTENDED_SIZE"))"
# Check if there are any files or folders left
if [[ "$FILETYPE" = "f" ]]; then
mvlogger "$REMAINING_UNATTENDED_FILES files remaining from unattended to primary ($(bytes_to_human "$REMAINING_UNATTENDED_SIZE"))"
else
mvlogger "$REMAINING_UNATTENDED_FOLDERS folders remaining from unattended to primary"
fi
fi
local direction
if [[ "$ACTION" =~ "unattended to secondary" ]]; then
direction="secondary"
elif [[ "$ACTION" =~ "unattended to primary" ]]; then
direction="primary"
fi
if [[ -n "$direction" ]]; then
# Check if there are any files or folders left
if [[ "$FILETYPE" = "f" ]]; then
mvlogger "$REMAINING_UNATTENDED_FILES files remaining from unattended to $direction ($(bytes_to_human "$REMAINING_UNATTENDED_SIZE"))"
else
mvlogger "$REMAINING_UNATTENDED_FOLDERS folders remaining from unattended to $direction"
fi
fi

else
if [[ "$SOURCE" =~ $PRIMARYSTORAGENAME ]]; then
REMAINING_CACHE_SIZE=$((REMAINING_CACHE_SIZE - FILESIZE))
# Check if there are any files or folders left
if [[ "$FILETYPE" = "f" ]]; then
REMAINING_CACHE_FILES=$((REMAINING_CACHE_FILES - NBLINKS))
mvlogger "$REMAINING_CACHE_FILES files remaining from caches to array ($(bytes_to_human "$REMAINING_CACHE_SIZE"))"
else
REMAINING_CACHE_FOLDERS=$((REMAINING_CACHE_FOLDERS - 1))
mvlogger "$REMAINING_CACHE_FOLDERS folders remaining from caches to array"
fi
mvlogger "$REMAINING_CACHE_FILES files remaining from caches to array ($(bytes_to_human "$REMAINING_CACHE_SIZE"))"
else
REMAINING_ARRAY_SIZE=$((REMAINING_ARRAY_SIZE - FILESIZE))
# Check if there are any files or folders left
if [[ "$FILETYPE" = "f" ]]; then
REMAINING_ARRAY_FILES=$((REMAINING_ARRAY_FILES - NBLINKS))
mvlogger "$REMAINING_ARRAY_FILES files remaining from array to caches ($(bytes_to_human "$REMAINING_ARRAY_SIZE"))"
else
REMAINING_ARRAY_FOLDERS=$((REMAINING_ARRAY_FOLDERS - 1))
mvlogger "$REMAINING_ARRAY_FOLDERS folders remaining from array to caches"
fi
mvlogger "$REMAINING_ARRAY_FILES files remaining from array to caches ($(bytes_to_human "$REMAINING_ARRAY_SIZE"))"
fi
Comment on lines 1946 to 1966

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

There is significant code duplication in this if/else block. The logic for decrementing counters and logging is repeated for both cache-to-array and array-to-cache movements. This can be refactored by using local variables to hold the context-specific values and then having a single block for logging. This will make the code more concise and easier to maintain.

                local log_msg
                if [[ "$SOURCE" =~ $PRIMARYSTORAGENAME ]]; then
                    REMAINING_CACHE_SIZE=$((REMAINING_CACHE_SIZE - FILESIZE))
                    # Check if there are any files or folders left
                    if [[ "$FILETYPE" = "f" ]]; then
                        REMAINING_CACHE_FILES=$((REMAINING_CACHE_FILES - NBLINKS))
                        log_msg="$REMAINING_CACHE_FILES files remaining from caches to array ($(bytes_to_human "$REMAINING_CACHE_SIZE"))"
                    else
                        REMAINING_CACHE_FOLDERS=$((REMAINING_CACHE_FOLDERS - 1))
                        log_msg="$REMAINING_CACHE_FOLDERS folders remaining from caches to array"
                    fi
                else
                    REMAINING_ARRAY_SIZE=$((REMAINING_ARRAY_SIZE - FILESIZE))
                    # Check if there are any files or folders left
                    if [[ "$FILETYPE" = "f" ]]; then
                        REMAINING_ARRAY_FILES=$((REMAINING_ARRAY_FILES - NBLINKS))
                        log_msg="$REMAINING_ARRAY_FILES files remaining from array to caches ($(bytes_to_human "$REMAINING_ARRAY_SIZE"))"
                    else
                        REMAINING_ARRAY_FOLDERS=$((REMAINING_ARRAY_FOLDERS - 1))
                        log_msg="$REMAINING_ARRAY_FOLDERS folders remaining from array to caches"
                    fi
                fi
                mvlogger "$log_msg"

fi
moverStatusWrite
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ omovercfg="no"
enableTurbo="no"
movefilesTool="rsync"
cleanFolders="no"
moveEmptyFolders="yes"
cleanDatasets="no"
synchronizeCache="no"
advancedOptions="no"
Expand Down