Skip to content

armgit / cua

Public Imported from GitHub
0

Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.

fix(lume): remove stale destination file before moving downloaded layer (#1209)

ddupont2343e739dac0
diff --git a/libs/lume/src/ContainerRegistry/ImageContainerRegistry.swift b/libs/lume/src/ContainerRegistry/ImageContainerRegistry.swift
index f9cbcccadc..cb93d7277f 100644
--- a/libs/lume/src/ContainerRegistry/ImageContainerRegistry.swift
+++ b/libs/lume/src/ContainerRegistry/ImageContainerRegistry.swift
@@ -2227,7 +2227,18 @@ class ImageContainerRegistry: ImageRegistry, @unchecked Sendable {
try FileManager.default.createDirectory(
at: url.deletingLastPathComponent(), withIntermediateDirectories: true)
- try FileManager.default.moveItem(at: tempURL, to: url)
+ do {
+ try FileManager.default.moveItem(at: tempURL, to: url)
+ } catch let moveError as NSError
+ where moveError.domain == NSCocoaErrorDomain
+ && moveError.code == NSFileWriteFileExistsError
+ {
+ // Destination already exists from a previous interrupted download.
+ // Use replaceItemAt for an atomic swap instead of the racy
+ // fileExists+removeItem+moveItem pattern.
+ _ = try FileManager.default.replaceItemAt(
+ url, withItemAt: tempURL, backupItemName: nil, options: [])
+ }
progress.addProgress(Int64(httpResponse.expectedContentLength))
// Always save a copy to the cache directory for use by copyFromCache,