vm: validate restore and switch backup names (#210)

This commit is contained in:
TastyHeadphones
2026-03-15 16:59:16 +09:00
committed by GitHub
parent a2fc0d37ca
commit 71b8f8e53b
2 changed files with 24 additions and 0 deletions

View File

@@ -11,6 +11,15 @@ BACKUPS_DIR="${BACKUPS_DIR:-vm.backups}"
NAME="${NAME:-}"
FORCE="${FORCE:-0}"
validate_backup_name() {
local name="$1"
local label="${2:-NAME}"
if [[ "$name" == */* || "$name" == .* ]]; then
echo "ERROR: ${label} must be a simple identifier (no slashes or leading dots)."
exit 1
fi
}
# --- Parse args ---
while [[ $# -gt 0 ]]; do
case "$1" in
@@ -39,6 +48,8 @@ if [[ -z "${NAME}" ]]; then
exit 1
fi
validate_backup_name "${NAME}"
SRC="${BACKUPS_DIR}/${NAME}"
# --- Validate backup ---

View File

@@ -13,6 +13,15 @@ BACKUPS_DIR="${BACKUPS_DIR:-vm.backups}"
NAME="${NAME:-}"
BACKUP_INCLUDE_IPSW="${BACKUP_INCLUDE_IPSW:-0}"
validate_backup_name() {
local name="$1"
local label="${2:-NAME}"
if [[ "$name" == */* || "$name" == .* ]]; then
echo "ERROR: ${label} must be a simple identifier (no slashes or leading dots)."
exit 1
fi
}
# --- Parse args ---
while [[ $# -gt 0 ]]; do
case "$1" in
@@ -41,6 +50,8 @@ if [[ -z "${NAME}" ]]; then
exit 1
fi
validate_backup_name "${NAME}"
TARGET="${BACKUPS_DIR}/${NAME}"
if [[ ! -d "${TARGET}" || ! -f "${TARGET}/config.plist" ]]; then
@@ -81,6 +92,8 @@ if [[ -d "${VM_DIR}" && -f "${VM_DIR}/config.plist" ]]; then
fi
fi
validate_backup_name "${CURRENT}" "Current VM name"
if [[ "${CURRENT}" == "${NAME}" ]]; then
echo "'${NAME}' is already the active VM."
exit 0