Skip to content

Commit 647ff01

Browse files
authored
Updated script to handle replacing files that already exist for the same name (#17)
* Updated script to handle replacing files that already exist for the same name
1 parent 1631fb6 commit 647ff01

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

copy-resources.sh

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#!/bin/bash
22

3+
# Exit immediately if a command exits with a non-zero status.
4+
set -ex
5+
36
# Define the source directory for the resources
47
SOURCE_DIR="resources"
58

@@ -9,23 +12,34 @@ DEST_DIR="vscode"
912
# Define paths for each file relative to the base directories
1013
# Format: "source_file_path:destination_file_path"
1114
FILES_TO_COPY=(
12-
"favicon.ico:src/sagemaker-code-editor/vscode/resources/server/favicon.ico"
13-
"code-icon.svg:src/sagemaker-code-editor/vscode/src/vs/workbench/browser/media/code-icon.svg"
14-
"letterpress-dark.svg:src/sagemaker-code-editor/vscode/src/vs/workbench/browser/parts/editor/media/letterpress-dark.svg"
15-
"letterpress-hcDark.svg:src/sagemaker-code-editor/vscode/src/vs/workbench/browser/parts/editor/media/letterpress-hcDark.svg"
16-
"letterpress-hcLight.svg:src/sagemaker-code-editor/vscode/src/vs/workbench/browser/parts/editor/media/letterpress-hcLight.svg"
17-
"letterpress-light.svg:src/sagemaker-code-editor/vscode/src/vs/workbench/browser/parts/editor/media/letterpress-light.svg"
15+
"favicon.ico:resources/server/favicon.ico"
16+
"code-icon.svg:src/vs/workbench/browser/media/code-icon.svg"
17+
"letterpress-dark.svg:src/vs/workbench/browser/parts/editor/media/letterpress-dark.svg"
18+
"letterpress-hcDark.svg:src/vs/workbench/browser/parts/editor/media/letterpress-hcDark.svg"
19+
"letterpress-hcLight.svg:src/vs/workbench/browser/parts/editor/media/letterpress-hcLight.svg"
20+
"letterpress-light.svg:src/vs/workbench/browser/parts/editor/media/letterpress-light.svg"
1821
)
1922

20-
# Loop through the file paths and copy each one to its new location
23+
# Loop through the file paths, check if file exists, and copy each one to its new location
2124
for FILE_PATH in "${FILES_TO_COPY[@]}"; do
2225
IFS=":" read -r SRC_FILE DEST_FILE <<< "$FILE_PATH"
2326

2427
# Construct full source and destination paths
2528
FULL_SRC_PATH="$SOURCE_DIR/$SRC_FILE"
2629
FULL_DEST_PATH="$DEST_DIR/$DEST_FILE"
2730

31+
# Check if the source file exists
32+
if [ ! -f "$FULL_SRC_PATH" ]; then
33+
echo "Error: Source file $FULL_SRC_PATH does not exist." >&2
34+
exit 1
35+
fi
36+
37+
# Check if the destination file exists. If so, delete it before copying.
38+
if [ -f "$FULL_DEST_PATH" ]; then
39+
rm "$FULL_DEST_PATH"
40+
echo "Existing file $FULL_DEST_PATH deleted."
41+
fi
42+
2843
# Copy file from source to destination
29-
cp "$FULL_SRC_PATH" "$FULL_DEST_PATH"
30-
echo "Copied $FULL_SRC_PATH to $FULL_DEST_PATH"
44+
cp -v "$FULL_SRC_PATH" "$FULL_DEST_PATH"
3145
done

0 commit comments

Comments
 (0)