Skip to content

Commit

Permalink
add validation
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangchiqing committed Jun 24, 2024
1 parent 1ec3e72 commit cebdce6
Showing 1 changed file with 47 additions and 9 deletions.
56 changes: 47 additions & 9 deletions tools/move-checkpoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,65 @@ fi
source_base=$(basename "$source_file_pattern")

# Extract the directory and base name from the destination file base
source_directory=$(dirname "$source_file_pattern")
destination_directory=$(dirname "$destination_file_base")
destination_base=$(basename "$destination_file_base")

# Create the destination directory if it doesn't exist
mkdir -p "$destination_directory"

# Loop through the source files and move them to the destination directory
for file in "$source_file_pattern"*;
do
if [ -f "$file" ]; then
# Define the expected files
expected_files=(
"$source_base"
"$source_base.001"
"$source_base.002"
"$source_base.003"
"$source_base.004"
"$source_base.005"
"$source_base.006"
"$source_base.007"
"$source_base.008"
"$source_base.009"
"$source_base.010"
"$source_base.011"
"$source_base.012"
"$source_base.013"
"$source_base.014"
"$source_base.015"
"$source_base.016"
)

# Check if all expected files are present
missing_files=()
for expected_file in "${expected_files[@]}"; do
full_expected_file="$source_directory/$expected_file"
if [ ! -f "$full_expected_file" ]; then
missing_files+=("$full_expected_file")
fi
done

if [ "${#missing_files[@]}" -ne 0 ]; then
echo "Error: The following expected files are missing:"
for file in "${missing_files[@]}"; do
echo " $file"
done
exit 1
fi

# Loop through the expected files and preview/move them to the destination directory
for file in "${expected_files[@]}"; do
full_source_file="$source_directory/$file"
if [ -f "$full_source_file" ]; then
# Get the file extension (if any)
extension="${file#$source_file_pattern}"
extension="${file#$source_base}"
# Construct the destination file name
destination_file="$destination_directory/$destination_base$extension"

# Preview or move the file
if [ "$run_mode" = true ]; then
echo "Moving: $(realpath "$file") -> $(realpath "$destination_file")"
mv "$file" "$destination_file"
echo "Moving: $(realpath "$full_source_file") -> $(realpath "$destination_file")"
mv "$full_source_file" "$destination_file"
else
echo "Preview: $(realpath "$file") -> $(realpath "$destination_file")"
echo "Preview: $(realpath "$full_source_file") -> $(realpath "$destination_file")"
fi
fi
done
Expand Down

0 comments on commit cebdce6

Please sign in to comment.