Skip to content

Commit

Permalink
Add comments to return statements to clarify
Browse files Browse the repository at this point in the history
  • Loading branch information
sandain committed Jan 2, 2021
1 parent 11090fc commit 9427216
Showing 1 changed file with 27 additions and 9 deletions.
36 changes: 27 additions & 9 deletions msctl
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,10 @@ getJavaMemory() {
serverRunning() {
# Try to determine if the world is running.
if [ $(getJavaPID "$1") -gt 0 ]; then
# Return a true value (success).
return 0
else
# Return a false value (failure).
return 1
fi
}
Expand Down Expand Up @@ -547,8 +549,10 @@ isWorldEnabled() {
local WORLDS
WORLDS=$(getEnabledWorlds)
if [ -n "$1" ] && listContains "$1" "$WORLDS"; then
# Return a true value (success).
return 0
else
# Return a false value (failure).
return 1
fi
}
Expand All @@ -563,8 +567,10 @@ isWorldDisabled() {
local WORLDS
WORLDS=$(getDisabledWorlds)
if [ -n "$1" ] && listContains "$1" "$WORLDS"; then
# Return a true value (success).
return 0
else
# Return a false value (failure).
return 1
fi
}
Expand All @@ -579,8 +585,10 @@ isWorldAvailable() {
local WORLDS
WORLDS=$(getAvailableWorlds)
if [ -n "$1" ] && listContains "$1" "$WORLDS"; then
# Return a true value (success).
return 0
else
# Return a false value (failure).
return 1
fi
}
Expand Down Expand Up @@ -1161,25 +1169,29 @@ createLockFile() {
# LOCKFILE exists, check to see if its process is running.
ps -p $PID >/dev/null 2>&1
if [ $? -eq 0 ]; then
# LOCKFILE exists and the process is running, return FALSE.
# LOCKFILE exists and the process is running.
# Return a false value (failure).
return 1
else
# Process not found assume it is not running.
echo $$ >$LOCKFILE
if [ $? -ne 0 ]; then
# Error creating LOCKFILE, return FALSE.
# Error creating LOCKFILE.
# Return a false value (failure).
return 1
fi
fi
else
# LOCKFILE does not exists.
echo $$ >$LOCKFILE
if [ $? -ne 0 ]; then
# Error creating LOCKFILE, return FALSE.
# Error creating LOCKFILE.
# Return a false value (failure).
return 1
fi
fi
# Success creating LOCKFILE, return TRUE.
# Success creating LOCKFILE.
# Return a true value (success).
return 0
}

Expand Down Expand Up @@ -1440,10 +1452,10 @@ worldBackup() {
# Make sure that the backup location exists.
if ! mkdir -p "$BACKUP_LOCATION"; then
echo "Error creating backup dir $BACKUP_LOCATION"
# Return a false value (failure).
return 1
fi
# Synchronize the mirror image of the world prior to closing, if
# required.
# Synchronize the mirror image of the world prior to closing, if required.
if [ $ENABLE_MIRROR -eq 1 ] && [ -L "$WORLDS_LOCATION/$1/$1" ] && [ -d "$MIRROR_PATH/$1" ]; then
syncMirrorImage $1
fi
Expand Down Expand Up @@ -1474,15 +1486,18 @@ worldBackup() {
# Create the backup.
if ! $RDIFF_BACKUP -v5 --print-statistics $EXCLUDE_OPTION "$WORLDS_LOCATION/$1" "$BACKUP_LOCATION/$1" >>"$BACKUP_LOG"; then
echo "Error doing backup of world $1"
# Return a false value (failure).
return 1
fi
# Cleanup old backups.
if [ $BACKUP_DURATION -gt 0 ]; then
if ! $RDIFF_BACKUP --remove-older-than ${BACKUP_DURATION}D --force "$BACKUP_LOCATION/$1" >>"$BACKUP_LOG"; then
echo "Error cleaning old backups of world $1"
# Return a false value (failure).
return 1
fi
fi
# Return a true value (success).
return 0
}

Expand Down Expand Up @@ -1521,10 +1536,12 @@ worldBackupRestore() {
else
echo "Restoring backup failed: $1 $2"
rm -rf "$TARGET_TMP"
# Return a false value (failure).
return 1
fi
else
echo "No backups found for world $1"
# Return a false value (failure).
return 1
fi
}
Expand Down Expand Up @@ -1983,7 +2000,7 @@ queryDetailedStatusJSON() {
queryNumUsers() {
local NUM_USERS
NUM_USERS=$(queryStatus $1 | cut -f6)
# Return 0 if query server not available
# Return 0 users if query server not available.
[ -z "$NUM_USERS" ] && NUM_USERS=0
printf "$NUM_USERS"
}
Expand Down Expand Up @@ -2418,9 +2435,10 @@ OVERVIEWER_URL=$(getDefaultsValue 'mscs-overviewer-url' 'http://overviewer.org')
MAPS_LOCATION=$(getDefaultsValue 'mscs-maps-location' $LOCATION'/maps')
MAPS_URL=$(getDefaultsValue 'mscs-maps-url' 'http://minecraft.server.com/maps')

# allow function importing via source command for tests
# Allow function importing via source command for tests.
if printf $0 | grep -qs "runtests\.sh"; then
# file was sourced, don't execute below here
# File was sourced, don't execute below here.
# Return a true value (success).
return 0
fi

Expand Down

0 comments on commit 9427216

Please sign in to comment.