From 685a53534b80a14efdfdb09ca00af984782ba6ee Mon Sep 17 00:00:00 2001 From: Jesse Gross Date: Thu, 1 Aug 2024 15:05:16 -0700 Subject: [PATCH] manifest: Don't prune layers if we can't open a manifest file If there is an error when opening a manifest file (corrupted, permission denied, etc.) then the referenced layers will not be included in the list of active layers. This causes them to be deleted when pruning happens at startup or a model is pulled. In such a situation, we should prefer to preserve data in the hopes that it can be recovered rather than being agressive about deletion. --- server/images.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/server/images.go b/server/images.go index 81357f3c..05875a88 100644 --- a/server/images.go +++ b/server/images.go @@ -714,8 +714,7 @@ func deleteUnusedLayers(skipModelPath *ModelPath, deleteMap map[string]struct{}) // save (i.e. delete from the deleteMap) any files used in other manifests manifest, _, err := GetManifest(fmp) if err != nil { - //nolint:nilerr - return nil + return err } for _, layer := range manifest.Layers { @@ -782,7 +781,8 @@ func PruneLayers() error { err = deleteUnusedLayers(nil, deleteMap) if err != nil { - return err + slog.Info(fmt.Sprintf("couldn't remove unused layers: %v", err)) + return nil } slog.Info(fmt.Sprintf("total unused blobs removed: %d", len(deleteMap))) @@ -971,7 +971,8 @@ func PullModel(ctx context.Context, name string, regOpts *registryOptions, fn fu fn(api.ProgressResponse{Status: "removing any unused layers"}) err = deleteUnusedLayers(nil, deleteMap) if err != nil { - return err + slog.Info(fmt.Sprintf("couldn't remove unused layers: %v", err)) + fn(api.ProgressResponse{Status: fmt.Sprintf("couldn't remove unused layers: %v", err)}) } }