-
-
Notifications
You must be signed in to change notification settings - Fork 945
fix(backend): make HTTP installs atomic and serialize with cache lock #6259
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -97,18 +97,36 @@ impl HttpBackend { | |||||||||
| let extracted_path = self.get_cached_extracted_path(cache_key); | ||||||||||
| let metadata_path = self.get_cache_metadata_path(cache_key); | ||||||||||
|
|
||||||||||
| // Create cache directory | ||||||||||
| file::create_dir_all(&cache_path)?; | ||||||||||
| // Ensure parent directory exists (we'll atomically rename into it) | ||||||||||
| if let Some(parent) = cache_path.parent() { | ||||||||||
| file::create_dir_all(parent)?; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| // Remove existing extracted contents if they exist | ||||||||||
| // Create a unique temporary directory for atomic extraction | ||||||||||
| let pid = std::process::id(); | ||||||||||
| let now_ms = SystemTime::now().duration_since(UNIX_EPOCH)?.as_millis(); | ||||||||||
| let tmp_dir_name = format!("{}.tmp-{}-{}", cache_key, pid, now_ms); | ||||||||||
| let tmp_extract_path = match cache_path.parent() { | ||||||||||
| Some(parent) => parent.join(tmp_dir_name), | ||||||||||
| None => cache_path.with_extension(format!("tmp-{}-{}", pid, now_ms)), | ||||||||||
| }; | ||||||||||
|
|
||||||||||
| // Ensure any previous temp dir is removed | ||||||||||
| if tmp_extract_path.exists() { | ||||||||||
| let _ = file::remove_all(&tmp_extract_path); | ||||||||||
|
||||||||||
| let _ = file::remove_all(&tmp_extract_path); | |
| if let Err(e) = file::remove_all(&tmp_extract_path) { | |
| eprintln!("Warning: Failed to remove temp directory {:?}: {}", tmp_extract_path, e); | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The temporary directory naming scheme uses process ID and timestamp but doesn't handle potential collisions if the same process creates multiple temp dirs within the same millisecond. Consider using a random component or atomic counter to ensure uniqueness.