| ... | ... |
@@ -686,10 +686,14 @@ func (container *Container) Mount() error {
|
| 686 | 686 |
return container.daemon.Mount(container) |
| 687 | 687 |
} |
| 688 | 688 |
|
| 689 |
+func (container *Container) changes() ([]archive.Change, error) {
|
|
| 690 |
+ return container.daemon.Changes(container) |
|
| 691 |
+} |
|
| 692 |
+ |
|
| 689 | 693 |
func (container *Container) Changes() ([]archive.Change, error) {
|
| 690 | 694 |
container.Lock() |
| 691 | 695 |
defer container.Unlock() |
| 692 |
- return container.daemon.Changes(container) |
|
| 696 |
+ return container.changes() |
|
| 693 | 697 |
} |
| 694 | 698 |
|
| 695 | 699 |
func (container *Container) GetImage() (*image.Image, error) {
|
| ... | ... |
@@ -750,7 +754,7 @@ func (container *Container) GetSize() (int64, int64) {
|
| 750 | 750 |
} |
| 751 | 751 |
defer container.Unmount() |
| 752 | 752 |
|
| 753 |
- if differ, ok := container.daemon.driver.(graphdriver.Differ); ok {
|
|
| 753 |
+ if differ, ok := driver.(graphdriver.Differ); ok {
|
|
| 754 | 754 |
sizeRw, err = differ.DiffSize(container.ID) |
| 755 | 755 |
if err != nil {
|
| 756 | 756 |
log.Errorf("Warning: driver %s couldn't return diff size of container %s: %s", driver, container.ID, err)
|
| ... | ... |
@@ -759,7 +763,7 @@ func (container *Container) GetSize() (int64, int64) {
|
| 759 | 759 |
sizeRw = -1 |
| 760 | 760 |
} |
| 761 | 761 |
} else {
|
| 762 |
- changes, _ := container.Changes() |
|
| 762 |
+ changes, _ := container.changes() |
|
| 763 | 763 |
if changes != nil {
|
| 764 | 764 |
sizeRw = archive.ChangesSize(container.basefs, changes) |
| 765 | 765 |
} else {
|
| ... | ... |
@@ -4,6 +4,7 @@ import ( |
| 4 | 4 |
"os/exec" |
| 5 | 5 |
"strings" |
| 6 | 6 |
"testing" |
| 7 |
+ "time" |
|
| 7 | 8 |
) |
| 8 | 9 |
|
| 9 | 10 |
func TestListContainers(t *testing.T) {
|
| ... | ... |
@@ -199,3 +200,39 @@ func assertContainerList(out string, expected []string) bool {
|
| 199 | 199 |
|
| 200 | 200 |
return true |
| 201 | 201 |
} |
| 202 |
+ |
|
| 203 |
+func TestListContainersSize(t *testing.T) {
|
|
| 204 |
+ name := "test_size" |
|
| 205 |
+ runCmd := exec.Command(dockerBinary, "run", "--name", name, "busybox", "sh", "-c", "echo 1 > test") |
|
| 206 |
+ out, _, err := runCommandWithOutput(runCmd) |
|
| 207 |
+ errorOut(err, t, out) |
|
| 208 |
+ id, err := getIDByName(name) |
|
| 209 |
+ if err != nil {
|
|
| 210 |
+ t.Fatal(err) |
|
| 211 |
+ } |
|
| 212 |
+ |
|
| 213 |
+ runCmd = exec.Command(dockerBinary, "ps", "-s", "-n=1") |
|
| 214 |
+ wait := make(chan struct{})
|
|
| 215 |
+ go func() {
|
|
| 216 |
+ out, _, err = runCommandWithOutput(runCmd) |
|
| 217 |
+ close(wait) |
|
| 218 |
+ }() |
|
| 219 |
+ select {
|
|
| 220 |
+ case <-wait: |
|
| 221 |
+ case <-time.After(3 * time.Second): |
|
| 222 |
+ t.Fatalf("Calling \"docker ps -s\" timed out!")
|
|
| 223 |
+ } |
|
| 224 |
+ errorOut(err, t, out) |
|
| 225 |
+ lines := strings.Split(strings.Trim(out, "\n "), "\n") |
|
| 226 |
+ sizeIndex := strings.Index(lines[0], "SIZE") |
|
| 227 |
+ idIndex := strings.Index(lines[0], "CONTAINER ID") |
|
| 228 |
+ foundID := lines[1][idIndex : idIndex+12] |
|
| 229 |
+ if foundID != id[:12] {
|
|
| 230 |
+ t.Fatalf("Expected id %s, got %s", id[:12], foundID)
|
|
| 231 |
+ } |
|
| 232 |
+ expectedSize := "2 B" |
|
| 233 |
+ foundSize := lines[1][sizeIndex:] |
|
| 234 |
+ if foundSize != expectedSize {
|
|
| 235 |
+ t.Fatalf("Expected size %q, got %q", expectedSize, foundSize)
|
|
| 236 |
+ } |
|
| 237 |
+} |