From 78095e4d122813b8f77f65be000766bc357816fd Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Thu, 18 Nov 2021 14:24:00 +0100 Subject: [PATCH] Remove unused image/v1 code This image format is only used for docker save / docker load. Signed-off-by: Sebastiaan van Stijn --- image/v1/imagev1.go | 33 +----------------------- image/v1/imagev1_test.go | 55 ---------------------------------------- 2 files changed, 1 insertion(+), 87 deletions(-) delete mode 100644 image/v1/imagev1_test.go diff --git a/image/v1/imagev1.go b/image/v1/imagev1.go index c341ceaa77..650897c5fa 100644 --- a/image/v1/imagev1.go +++ b/image/v1/imagev1.go @@ -2,7 +2,6 @@ package v1 // import "github.com/docker/docker/image/v1" import ( "encoding/json" - "reflect" "strings" "github.com/docker/docker/api/types/versions" @@ -16,7 +15,7 @@ import ( // noFallbackMinVersion is the minimum version for which v1compatibility // information will not be marshaled through the Image struct to remove // blank fields. -var noFallbackMinVersion = "1.8.3" +const noFallbackMinVersion = "1.8.3" // HistoryFromConfig creates a History struct from v1 configuration JSON func HistoryFromConfig(imageJSON []byte, emptyLayer bool) (image.History, error) { @@ -106,36 +105,6 @@ func MakeConfigFromV1Config(imageJSON []byte, rootfs *image.RootFS, history []im return json.Marshal(c) } -// MakeV1ConfigFromConfig creates a legacy V1 image config from an Image struct -func MakeV1ConfigFromConfig(img *image.Image, v1ID, parentV1ID string, throwaway bool) ([]byte, error) { - // Top-level v1compatibility string should be a modified version of the - // image config. - var configAsMap map[string]*json.RawMessage - if err := json.Unmarshal(img.RawJSON(), &configAsMap); err != nil { - return nil, err - } - - // Delete fields that didn't exist in old manifest - imageType := reflect.TypeOf(img).Elem() - for i := 0; i < imageType.NumField(); i++ { - f := imageType.Field(i) - jsonName := strings.Split(f.Tag.Get("json"), ",")[0] - // Parent is handled specially below. - if jsonName != "" && jsonName != "parent" { - delete(configAsMap, jsonName) - } - } - configAsMap["id"] = rawJSON(v1ID) - if parentV1ID != "" { - configAsMap["parent"] = rawJSON(parentV1ID) - } - if throwaway { - configAsMap["throwaway"] = rawJSON(true) - } - - return json.Marshal(configAsMap) -} - func rawJSON(value interface{}) *json.RawMessage { jsonval, err := json.Marshal(value) if err != nil { diff --git a/image/v1/imagev1_test.go b/image/v1/imagev1_test.go deleted file mode 100644 index 45ae783d18..0000000000 --- a/image/v1/imagev1_test.go +++ /dev/null @@ -1,55 +0,0 @@ -package v1 // import "github.com/docker/docker/image/v1" - -import ( - "encoding/json" - "testing" - - "github.com/docker/docker/image" -) - -func TestMakeV1ConfigFromConfig(t *testing.T) { - img := &image.Image{ - V1Image: image.V1Image{ - ID: "v2id", - Parent: "v2parent", - OS: "os", - }, - OSVersion: "osversion", - RootFS: &image.RootFS{ - Type: "layers", - }, - } - v2js, err := json.Marshal(img) - if err != nil { - t.Fatal(err) - } - - // Convert the image back in order to get RawJSON() support. - img, err = image.NewFromJSON(v2js) - if err != nil { - t.Fatal(err) - } - - js, err := MakeV1ConfigFromConfig(img, "v1id", "v1parent", false) - if err != nil { - t.Fatal(err) - } - - newimg := &image.Image{} - err = json.Unmarshal(js, newimg) - if err != nil { - t.Fatal(err) - } - - if newimg.V1Image.ID != "v1id" || newimg.Parent != "v1parent" { - t.Error("ids should have changed", newimg.V1Image.ID, newimg.V1Image.Parent) - } - - if newimg.RootFS != nil { - t.Error("rootfs should have been removed") - } - - if newimg.V1Image.OS != "os" { - t.Error("os should have been preserved") - } -}