2015-03-25 03:57:23 +00:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
2015-04-02 22:52:34 +00:00
|
|
|
"encoding/json"
|
2015-03-25 03:57:23 +00:00
|
|
|
"fmt"
|
|
|
|
|
2015-04-02 22:52:34 +00:00
|
|
|
"github.com/docker/docker/api/types"
|
2015-03-25 03:57:23 +00:00
|
|
|
"github.com/docker/docker/pkg/archive"
|
|
|
|
flag "github.com/docker/docker/pkg/mflag"
|
|
|
|
)
|
|
|
|
|
2015-03-25 17:34:41 +00:00
|
|
|
// CmdDiff shows changes on a container's filesystem.
|
|
|
|
//
|
2015-04-02 22:52:34 +00:00
|
|
|
// Each changed file is printed on a separate line, prefixed with a single
|
|
|
|
// character that indicates the status of the file: C (modified), A (added),
|
|
|
|
// or D (deleted).
|
2015-03-25 17:34:41 +00:00
|
|
|
//
|
|
|
|
// Usage: docker diff CONTAINER
|
2015-03-25 03:57:23 +00:00
|
|
|
func (cli *DockerCli) CmdDiff(args ...string) error {
|
2015-05-14 02:45:01 +00:00
|
|
|
cmd := cli.Subcmd("diff", []string{"CONTAINER"}, "Inspect changes on a container's filesystem", true)
|
2015-03-25 03:57:23 +00:00
|
|
|
cmd.Require(flag.Exact, 1)
|
2015-07-03 09:26:09 +00:00
|
|
|
|
2015-03-29 01:22:46 +00:00
|
|
|
cmd.ParseFlags(args, true)
|
2015-03-25 03:57:23 +00:00
|
|
|
|
2015-04-10 16:53:40 +00:00
|
|
|
if cmd.Arg(0) == "" {
|
|
|
|
return fmt.Errorf("Container name cannot be empty")
|
|
|
|
}
|
|
|
|
|
2015-05-14 01:36:36 +00:00
|
|
|
rdr, _, _, err := cli.call("GET", "/containers/"+cmd.Arg(0)+"/changes", nil, nil)
|
2015-03-25 03:57:23 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2015-07-03 06:19:23 +00:00
|
|
|
defer rdr.Close()
|
|
|
|
|
2015-04-02 22:52:34 +00:00
|
|
|
changes := []types.ContainerChange{}
|
2015-04-26 16:50:25 +00:00
|
|
|
if err := json.NewDecoder(rdr).Decode(&changes); err != nil {
|
2015-03-25 03:57:23 +00:00
|
|
|
return err
|
|
|
|
}
|
2015-04-02 22:52:34 +00:00
|
|
|
|
|
|
|
for _, change := range changes {
|
2015-03-25 03:57:23 +00:00
|
|
|
var kind string
|
2015-04-02 22:52:34 +00:00
|
|
|
switch change.Kind {
|
2015-03-25 03:57:23 +00:00
|
|
|
case archive.ChangeModify:
|
|
|
|
kind = "C"
|
|
|
|
case archive.ChangeAdd:
|
|
|
|
kind = "A"
|
|
|
|
case archive.ChangeDelete:
|
|
|
|
kind = "D"
|
|
|
|
}
|
2015-04-02 22:52:34 +00:00
|
|
|
fmt.Fprintf(cli.out, "%s %s\n", kind, change.Path)
|
2015-03-25 03:57:23 +00:00
|
|
|
}
|
2015-04-02 22:52:34 +00:00
|
|
|
|
2015-03-25 03:57:23 +00:00
|
|
|
return nil
|
|
|
|
}
|