Description: add command applayer-rename 
 docker-ce (5:20.10.3-18) buster; urgency=low
 .
   * Version: 20.10.3-18
   * add command applayer-rename 
Author: wanghuaiqing <wanghuaiqing@loongson.com>

---
The information above should follow the Patch Tagging Guidelines, please
checkout http://dep.debian.net/deps/dep3/ to learn about the format. Here
are templates for supplementary fields that you might want to add:

Origin: <vendor|upstream|other>, <url of original patch>
Bug: <url in upstream bugtracker>
Bug-Debian: https://bugs.debian.org/<bugnumber>
Bug-Ubuntu: https://launchpad.net/bugs/<bugnumber>
Forwarded: <no|not-needed|url proving that it has been forwarded>
Reviewed-By: <name and email of someone who approved the patch>
Last-Update: 2022-06-22

--- lcf-utils-1.0.1/src/loongker-ce-20.10.3.orig/sources/cli/cli/command/commands/commands.go
+++ lcf-utils-1.0.1/src/loongker-ce-20.10.3/sources/cli/cli/command/commands/commands.go
@@ -131,6 +131,7 @@ func AddCommands(cmd *cobra.Command, doc
 		hide(image.NewAppComposeCommand(dockerCli)),
 		hide(image.NewLoadAppCommand(dockerCli)),
 		hide(image.NewSaveAppCommand(dockerCli)),
+		hide(image.NewApplayerRenameCommand(dockerCli)),
 	)
 }
 
--- /dev/null
+++ lcf-utils-1.0.1/src/loongker-ce-20.10.3/sources/cli/cli/command/image/rename.go
@@ -0,0 +1,40 @@
+package image
+
+import (
+	"context"
+
+	"github.com/docker/cli/cli"
+	"github.com/docker/cli/cli/command"
+	"github.com/spf13/cobra"
+)
+
+type renameOptions struct {
+	oldName string
+	newName string
+}
+
+func NewApplayerRenameCommand(dockerCli command.Cli) *cobra.Command {
+	var opts renameOptions
+
+	cmd := &cobra.Command{
+		Use:   "applayer-rename applayerid/oldname newname",
+		Short: "rename the name of applayer",
+		Args:  cli.ExactArgs(2),
+		RunE: func(cmd *cobra.Command, args []string) error {
+			opts.oldName = args[0]
+			opts.newName = args[1]
+			return runRename(dockerCli, opts)
+		},
+	}
+
+	flags := cmd.Flags()
+	flags.SetInterspersed(false)
+
+	return cmd
+}
+
+func runRename(dockerCli command.Cli, opts renameOptions) error {
+	ctx := context.Background()
+
+	return dockerCli.Client().ApplayerRename(ctx, opts.oldName, opts.newName)
+}
--- /dev/null
+++ lcf-utils-1.0.1/src/loongker-ce-20.10.3/sources/cli/vendor/github.com/docker/docker/client/applayer_rename.go
@@ -0,0 +1,18 @@
+package client // import "github.com/docker/docker/client"
+
+import (
+	"context"
+	"net/url"
+)
+
+// ImageTag tags an image in the docker host
+func (cli *Client) ApplayerRename(ctx context.Context, oldName, newName string) error {
+
+	query := url.Values{}
+	query.Set("oldName", oldName)
+	query.Set("newName", newName)
+
+	resp, err := cli.post(ctx, "/applayers/rename", query, nil, nil)
+	ensureReaderClosed(resp)
+	return err
+}
--- lcf-utils-1.0.1/src/loongker-ce-20.10.3.orig/sources/cli/vendor/github.com/docker/docker/client/interface.go
+++ lcf-utils-1.0.1/src/loongker-ce-20.10.3/sources/cli/vendor/github.com/docker/docker/client/interface.go
@@ -111,6 +111,7 @@ type ImageAPIClient interface {
 	Appcompose(ctx context.Context) error
 	AppSave(ctx context.Context, idorName string) (io.ReadCloser, error)
 	AppLoad(ctx context.Context, input io.Reader, quiet bool) (types.ImageLoadResponse, error)
+	ApplayerRename(ctx context.Context, oldName, newName string) error
 }
 
 // NetworkAPIClient defines API client methods for the networks
--- lcf-utils-1.0.1/src/loongker-ce-20.10.3.orig/sources/engine/api/server/router/image/backend.go
+++ lcf-utils-1.0.1/src/loongker-ce-20.10.3/sources/engine/api/server/router/image/backend.go
@@ -29,6 +29,7 @@ type imageBackend interface {
 	ImagesPrune(ctx context.Context, pruneFilters filters.Args) (*types.ImagesPruneReport, error)
 	ImageGenApplayer(imageRef string, appname string, outStream io.Writer, quiet bool) error
 	ApplayerDelete(idorName string) (*types.AppLayerDeleteResponse, error)
+	ApplayerRename(idorName string, newName string) error
 	Appcompose() error
 }
 
--- lcf-utils-1.0.1/src/loongker-ce-20.10.3.orig/sources/engine/api/server/router/image/image.go
+++ lcf-utils-1.0.1/src/loongker-ce-20.10.3/sources/engine/api/server/router/image/image.go
@@ -45,6 +45,7 @@ func (r *imageRouter) initRoutes() {
 		router.NewPostRoute("/images/loadupgrade", r.postUpgradeImageLoad),
 		router.NewPostRoute("/images/appcompose", r.postAppcompose),
 		router.NewPostRoute("/applayers/loadapp", r.postAppLoad),
+		router.NewPostRoute("/applayers/rename", r.postApplayerName),
 		// DELETE
 		router.NewDeleteRoute("/images/{name:.*}", r.deleteImages),
 		router.NewDeleteRoute("/applayers/{name:.*}", r.deleteApplayer),
--- lcf-utils-1.0.1/src/loongker-ce-20.10.3.orig/sources/engine/api/server/router/image/image_routes.go
+++ lcf-utils-1.0.1/src/loongker-ce-20.10.3/sources/engine/api/server/router/image/image_routes.go
@@ -219,6 +219,25 @@ func (s *imageRouter) postAppLoad(ctx co
 	return nil
 }
 
+func (s *imageRouter) postApplayerName(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
+	if err := httputils.ParseForm(r); err != nil {
+		return err
+	}
+
+	oldName := r.Form.Get("oldName")
+	newName := r.Form.Get("newName")
+
+	if strings.TrimSpace(oldName) == "" {
+		return missingApplayerError{}
+	}
+
+	if strings.TrimSpace(newName) == "" {
+		return missingApplayerError{}
+	}
+
+	return s.backend.ApplayerRename(oldName, newName)
+}
+
 func (s *imageRouter) getUpgradeImageGet(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
 	if err := httputils.ParseForm(r); err != nil {
 		return err
--- /dev/null
+++ lcf-utils-1.0.1/src/loongker-ce-20.10.3/sources/engine/daemon/images/applayer_rename.go
@@ -0,0 +1,28 @@
+package images // import "github.com/docker/docker/daemon/images"
+
+import (
+
+	"github.com/pkg/errors"
+	"github.com/docker/distribution/reference"
+)
+
+
+func (i *ImageService) ApplayerRename(idorName string, newName string) error {
+
+	_, err := reference.ParseNormalizedNamed(newName)
+	if err != nil {
+		return errors.Errorf("applayer newname %s contains invalid character", newName)
+	}
+
+	id, err := i.applayerStore.Search(idorName)
+	if err != nil {
+		id, err = i.applayerStore.GetByName(idorName)
+		if err != nil {
+			return err
+		}
+	}
+	err = i.applayerStore.Rename(id, newName)
+	return err
+}
+
+
--- lcf-utils-1.0.1/src/loongker-ce-20.10.3.orig/sources/engine/image/applayer_store.go
+++ lcf-utils-1.0.1/src/loongker-ce-20.10.3/sources/engine/image/applayer_store.go
@@ -50,6 +50,7 @@ type ApplayerStore interface {
 	Search(partialID string) (ID, error)
 	Map() map[ID]AppLayer
 	Len() int
+	Rename(id ID, newName string) error
 	LockId(id string)
 	UnlockId(id string)
 }
@@ -429,6 +430,23 @@ func (as *applayerstore) GetByName(name
 	return id, nil
 }
 
+func (as *applayerstore) Rename(id ID, newName string) error {
+	as.Lock()
+	defer as.Unlock()
+	al := as.applayers[id]
+	if nil == al {
+		return fmt.Errorf("func AlterName failed to get applayer: %v", id)
+	}
+	id_temp := as.nameSet[newName]
+	if "" != id_temp {
+		return fmt.Errorf("func AlterName applayer: %s has existed, please try others", newName)
+	}
+	delete(as.nameSet, al.name)
+	al.name = newName
+	as.fs.SetName(id.Digest(), newName)
+	as.nameSet[newName]=id
+	return nil
+}
 type applayerDeleteConflict struct {
 	refcount     int
 	applayerID   ID
