2015-03-24 23:57:23 -04:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
2015-04-02 18:52:34 -04:00
|
|
|
"encoding/json"
|
2015-03-24 23:57:23 -04:00
|
|
|
"fmt"
|
|
|
|
|
2015-04-02 18:52:34 -04:00
|
|
|
"github.com/docker/docker/api/types"
|
2015-03-24 23:57:23 -04:00
|
|
|
"github.com/docker/docker/pkg/archive"
|
|
|
|
flag "github.com/docker/docker/pkg/mflag"
|
|
|
|
)
|
|
|
|
|
2015-03-25 13:34:41 -04:00
|
|
|
// CmdDiff shows changes on a container's filesystem.
|
|
|
|
//
|
2015-04-02 18:52:34 -04: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 13:34:41 -04:00
|
|
|
//
|
|
|
|
// Usage: docker diff CONTAINER
|
2015-03-24 23:57:23 -04:00
|
|
|
func (cli *DockerCli) CmdDiff(args ...string) error {
|
2015-05-13 22:45:01 -04:00
|
|
|
cmd := cli.Subcmd("diff", []string{"CONTAINER"}, "Inspect changes on a container's filesystem", true)
|
2015-03-24 23:57:23 -04:00
|
|
|
cmd.Require(flag.Exact, 1)
|
2015-07-03 05:26:09 -04:00
|
|
|
|
2015-03-28 21:22:46 -04:00
|
|
|
cmd.ParseFlags(args, true)
|
2015-03-24 23:57:23 -04:00
|
|
|
|
2015-04-10 12:53:40 -04:00
|
|
|
if cmd.Arg(0) == "" {
|
|
|
|
return fmt.Errorf("Container name cannot be empty")
|
|
|
|
}
|
|
|
|
|
2015-07-09 22:05:50 -04:00
|
|
|
serverResp, err := cli.call("GET", "/containers/"+cmd.Arg(0)+"/changes", nil, nil)
|
2015-03-24 23:57:23 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2015-07-09 22:05:50 -04:00
|
|
|
defer serverResp.body.Close()
|
2015-07-03 02:19:23 -04:00
|
|
|
|
2015-04-02 18:52:34 -04:00
|
|
|
changes := []types.ContainerChange{}
|
2015-07-09 22:05:50 -04:00
|
|
|
if err := json.NewDecoder(serverResp.body).Decode(&changes); err != nil {
|
2015-03-24 23:57:23 -04:00
|
|
|
return err
|
|
|
|
}
|
2015-04-02 18:52:34 -04:00
|
|
|
|
|
|
|
for _, change := range changes {
|
2015-03-24 23:57:23 -04:00
|
|
|
var kind string
|
2015-04-02 18:52:34 -04:00
|
|
|
switch change.Kind {
|
2015-03-24 23:57:23 -04:00
|
|
|
case archive.ChangeModify:
|
|
|
|
kind = "C"
|
|
|
|
case archive.ChangeAdd:
|
|
|
|
kind = "A"
|
|
|
|
case archive.ChangeDelete:
|
|
|
|
kind = "D"
|
|
|
|
}
|
2015-04-02 18:52:34 -04:00
|
|
|
fmt.Fprintf(cli.out, "%s %s\n", kind, change.Path)
|
2015-03-24 23:57:23 -04:00
|
|
|
}
|
2015-04-02 18:52:34 -04:00
|
|
|
|
2015-03-24 23:57:23 -04:00
|
|
|
return nil
|
|
|
|
}
|