From 4589058fdb5369f4addc57e55deba10db95cebec Mon Sep 17 00:00:00 2001 From: Quanyi Ma Date: Tue, 10 Sep 2024 16:46:30 +0800 Subject: [PATCH] Fix the sync crates file path error Signed-off-by: Quanyi Ma --- atlas/README.md | 1 + scripts/crates-sync/crates-sync.py | 34 ++++++++++++++++++++---------- 2 files changed, 24 insertions(+), 11 deletions(-) create mode 100644 atlas/README.md diff --git a/atlas/README.md b/atlas/README.md new file mode 100644 index 000000000..aa83442e5 --- /dev/null +++ b/atlas/README.md @@ -0,0 +1 @@ +## Atlas Module diff --git a/scripts/crates-sync/crates-sync.py b/scripts/crates-sync/crates-sync.py index c9e2a5d90..e710c6568 100755 --- a/scripts/crates-sync/crates-sync.py +++ b/scripts/crates-sync/crates-sync.py @@ -1,12 +1,12 @@ -import os # For file and directory operations -import sys # For system-specific parameters and functions -import json # For JSON parsing -import urllib.request # For downloading files from URLs -import tarfile # For handling tar archives -import subprocess # For running system commands -import shutil # For high-level file operations -from collections import defaultdict # For creating dictionaries with default values -from packaging import version # For parsing and comparing version numbers +import os +import sys +import json +import urllib.request +import tarfile +import subprocess +import shutil +from collections import defaultdict +from packaging import version def ensure_directory(path): # Create a directory if it doesn't exist @@ -77,8 +77,20 @@ def filter_member(tarinfo, filterpath): print(f"Warning: Empty crate file {crate_path}. Skipping extraction.") return False - # Extract directly to the target directory - safe_extract(tar, extract_path) + # Create a temporary directory for extraction + temp_extract_path = extract_path + "_temp" + ensure_directory(temp_extract_path) + + # Extract to the temporary directory + safe_extract(tar, temp_extract_path) + + # Move contents from the nested directory to the target directory + nested_dir = os.path.join(temp_extract_path, os.listdir(temp_extract_path)[0]) + for item in os.listdir(nested_dir): + shutil.move(os.path.join(nested_dir, item), extract_path) + + # Remove the temporary directory + shutil.rmtree(temp_extract_path) print(f"Extracted version to {extract_path}") return True