-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tart pull: try to re-use local VM image layers to speed-up the pulling (
#825) * Remove unused pullFromRegistry() method with "reference" argument * tart pull: try to deduplicate disk layers to speed-up the pulling
- Loading branch information
Showing
6 changed files
with
93 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import Foundation | ||
|
||
struct LocalLayerCache { | ||
private let mappedDisk: Data | ||
private var digestToRange: [String : Range<Data.Index>] = [:] | ||
|
||
init?(_ diskURL: URL, _ manifest: OCIManifest) throws { | ||
// mmap(2) the disk that contains the layers from the manifest | ||
self.mappedDisk = try Data(contentsOf: diskURL, options: [.alwaysMapped]) | ||
|
||
// Record the ranges of the disk layers listed in the manifest | ||
var offset: UInt64 = 0 | ||
|
||
for layer in manifest.layers.filter({ $0.mediaType == diskV2MediaType }) { | ||
guard let uncompressedSize = layer.uncompressedSize() else { | ||
return nil | ||
} | ||
|
||
self.digestToRange[layer.digest] = Int(offset)..<Int(offset+uncompressedSize) | ||
|
||
offset += uncompressedSize | ||
} | ||
} | ||
|
||
func find(_ digest: String) -> Data? { | ||
guard let foundRange = self.digestToRange[digest] else { | ||
return nil | ||
} | ||
|
||
return self.mappedDisk.subdata(in: foundRange) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters