Skip to content

Commit 68df5dc

Browse files
committed
update pr
1 parent 267fa2b commit 68df5dc

File tree

1 file changed

+36
-25
lines changed

1 file changed

+36
-25
lines changed

eng/scripts/get-aspire-cli-pr.sh

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,39 @@ get_runtime_identifier() {
288288
printf "%s" "${target_os}-${target_arch}"
289289
}
290290

291+
# Create a temporary directory with a prefix. Honors DRY_RUN
292+
new_temp_dir() {
293+
local prefix="$1"
294+
if [[ "$DRY_RUN" == true ]]; then
295+
printf "/tmp/%s-whatif" "$prefix"
296+
return 0
297+
fi
298+
local dir
299+
if ! dir=$(mktemp -d -t "${prefix}-XXXXXXXX"); then
300+
say_error "Unable to create temporary directory"
301+
return 1
302+
fi
303+
say_verbose "Creating temporary directory: $dir"
304+
printf "%s" "$dir"
305+
}
306+
307+
# Remove a temporary directory unless KEEP_ARCHIVE is set. Honors DRY_RUN
308+
remove_temp_dir() {
309+
local dir="$1"
310+
if [[ -z "$dir" || ! -d "$dir" ]]; then
311+
return 0
312+
fi
313+
if [[ "$DRY_RUN" == true ]]; then
314+
return 0
315+
fi
316+
if [[ "$KEEP_ARCHIVE" != true ]]; then
317+
say_verbose "Cleaning up temporary files..."
318+
rm -rf "$dir" || say_warn "Failed to clean up temporary directory: $dir"
319+
else
320+
printf "Archive files kept in: %s\n" "$dir"
321+
fi
322+
}
323+
291324
# Function to install/unpack archive files
292325
install_archive() {
293326
local archive_file="$1"
@@ -307,30 +340,26 @@ install_archive() {
307340
fi
308341

309342
# Check archive format and extract accordingly
310-
if [[ "$archive_file" == *.zip ]]; then
311-
# Use unzip for ZIP files
343+
if [[ "$archive_file" =~ \.zip$ ]]; then
312344
if ! command -v unzip >/dev/null 2>&1; then
313345
say_error "unzip command not found. Please install unzip to extract ZIP files."
314346
return 1
315347
fi
316-
317348
if ! unzip -o "$archive_file" -d "$destination_path"; then
318349
say_error "Failed to extract ZIP archive: $archive_file"
319350
return 1
320351
fi
321-
elif [[ "$archive_file" == *.tar.gz ]]; then
322-
# Use tar for tar.gz files on Unix systems
352+
elif [[ "$archive_file" =~ \.tar\.gz$ ]]; then
323353
if ! command -v tar >/dev/null 2>&1; then
324354
say_error "tar command not found. Please install tar to extract tar.gz files."
325355
return 1
326356
fi
327-
328357
if ! tar -xzf "$archive_file" -C "$destination_path"; then
329358
say_error "Failed to extract tar.gz archive: $archive_file"
330359
return 1
331360
fi
332361
else
333-
say_error "Unsupported archive format: $archive_file. Only .zip and .tar.gz are supported."
362+
say_error "Unsupported archive format: $archive_file. Only .zip and .tar.gz files are supported."
334363
return 1
335364
fi
336365

@@ -457,24 +486,6 @@ add_to_shell_profile() {
457486
return 0
458487
}
459488

460-
# Cleanup function for temporary directory
461-
cleanup() {
462-
# shellcheck disable=SC2317 # Function is called via trap
463-
if [[ "$DRY_RUN" == true ]]; then
464-
# No cleanup needed in dry-run mode
465-
return 0
466-
fi
467-
468-
if [[ -n "${temp_dir:-}" ]] && [[ -d "$temp_dir" ]]; then
469-
if [[ "$KEEP_ARCHIVE" != true ]]; then
470-
say_verbose "Cleaning up temporary files..."
471-
rm -rf "$temp_dir" || say_warn "Failed to clean up temporary directory: $temp_dir"
472-
else
473-
printf "Archive files kept in: %s\n" "$temp_dir"
474-
fi
475-
fi
476-
}
477-
478489
# =============================================================================
479490
# END: Shared code
480491
# =============================================================================

0 commit comments

Comments
 (0)