diff --git a/Utility/Lock.sh b/Utility/Lock.sh index 75834d1..1a7b648 100644 --- a/Utility/Lock.sh +++ b/Utility/Lock.sh @@ -5,21 +5,37 @@ if [[ ! -w "$LOCK_DIR" ]]; then LOCK_DIR="/tmp" # Fallback für benutzerspezifische Locks fi -LOCK_FILE="$LOCK_DIR/$(basename "$0").lock" +# Funktion zur Erstellung des Lock-Dateinamens +get_lock_file() { + local suffix="$1" + if [[ -n "$suffix" ]]; then + echo "$LOCK_DIR/$(basename "$0")_$suffix.lock" + else + echo "$LOCK_DIR/$(basename "$0").lock" + fi +} create_lock() { - if [[ -e "$LOCK_FILE" ]]; then - log "Ein anderer Prozess läuft bereits. Lock-File gefunden: $LOCK_FILE" + local suffix="$1" + local lock_file + lock_file=$(get_lock_file "$suffix") + + if [[ -e "$lock_file" ]]; then + log "Ein anderer Prozess läuft bereits. Lock-File gefunden: $lock_file" exit 1 fi - touch "$LOCK_FILE" - log "Lock-File erstellt: $LOCK_FILE" + touch "$lock_file" + log "Lock-File erstellt: $lock_file" } remove_lock() { - if [[ -e "$LOCK_FILE" ]]; then - rm -f "$LOCK_FILE" - log "Lock-File entfernt: $LOCK_FILE" + local suffix="$1" + local lock_file + lock_file=$(get_lock_file "$suffix") + + if [[ -e "$lock_file" ]]; then + rm -f "$lock_file" + log "Lock-File entfernt: $lock_file" fi }