chunked: cache all the files with the same digest
this is a preparation change for the next commit. Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
parent
31d1330f74
commit
d00974a9aa
|
|
@ -112,14 +112,14 @@ func copyFileContent(srcFd int, destFile string, dirfd int, mode os.FileMode, us
|
||||||
return dstFile, st.Size(), err
|
return dstFile, st.Size(), err
|
||||||
}
|
}
|
||||||
|
|
||||||
func prepareOtherLayersCache(layersMetadata map[string][]internal.FileMetadata) map[string]map[string]*internal.FileMetadata {
|
func prepareOtherLayersCache(layersMetadata map[string][]internal.FileMetadata) map[string]map[string][]*internal.FileMetadata {
|
||||||
maps := make(map[string]map[string]*internal.FileMetadata)
|
maps := make(map[string]map[string][]*internal.FileMetadata)
|
||||||
|
|
||||||
for layerID, v := range layersMetadata {
|
for layerID, v := range layersMetadata {
|
||||||
r := make(map[string]*internal.FileMetadata)
|
r := make(map[string][]*internal.FileMetadata)
|
||||||
for i := range v {
|
for i := range v {
|
||||||
if v[i].Digest != "" {
|
if v[i].Digest != "" {
|
||||||
r[v[i].Digest] = &v[i]
|
r[v[i].Digest] = append(r[v[i].Digest], &v[i])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
maps[layerID] = r
|
maps[layerID] = r
|
||||||
|
|
@ -243,20 +243,21 @@ func copyFileFromOtherLayer(file internal.FileMetadata, source string, otherFile
|
||||||
// layersMetadata contains the metadata for each layer in the storage.
|
// layersMetadata contains the metadata for each layer in the storage.
|
||||||
// layersTarget maps each layer to its checkout on disk.
|
// layersTarget maps each layer to its checkout on disk.
|
||||||
// useHardLinks defines whether the deduplication can be performed using hard links.
|
// useHardLinks defines whether the deduplication can be performed using hard links.
|
||||||
func findFileInOtherLayers(file internal.FileMetadata, dirfd int, layersMetadata map[string]map[string]*internal.FileMetadata, layersTarget map[string]string, useHardLinks bool) (bool, *os.File, int64, error) {
|
func findFileInOtherLayers(file internal.FileMetadata, dirfd int, layersMetadata map[string]map[string][]*internal.FileMetadata, layersTarget map[string]string, useHardLinks bool) (bool, *os.File, int64, error) {
|
||||||
// this is ugly, needs to be indexed
|
// this is ugly, needs to be indexed
|
||||||
for layerID, checksums := range layersMetadata {
|
for layerID, checksums := range layersMetadata {
|
||||||
m, found := checksums[file.Digest]
|
m, found := checksums[file.Digest]
|
||||||
if !found {
|
if !found {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
source, ok := layersTarget[layerID]
|
source, ok := layersTarget[layerID]
|
||||||
if !ok {
|
if !ok || len(source) == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
found, dstFile, written, err := copyFileFromOtherLayer(file, source, m, dirfd, useHardLinks)
|
otherFile := m[0]
|
||||||
|
|
||||||
|
found, dstFile, written, err := copyFileFromOtherLayer(file, source, otherFile, dirfd, useHardLinks)
|
||||||
if found && err == nil {
|
if found && err == nil {
|
||||||
return found, dstFile, written, err
|
return found, dstFile, written, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue