|
@@ -3,12 +3,12 @@ package graphtest // import "github.com/docker/docker/daemon/graphdriver/graphte
|
|
|
import (
|
|
|
"bytes"
|
|
|
"fmt"
|
|
|
+ "io/fs"
|
|
|
"math/rand"
|
|
|
"os"
|
|
|
"path/filepath"
|
|
|
"sort"
|
|
|
|
|
|
- "github.com/containerd/continuity/driver"
|
|
|
"github.com/docker/docker/daemon/graphdriver"
|
|
|
"github.com/docker/docker/pkg/archive"
|
|
|
"github.com/docker/docker/pkg/stringid"
|
|
@@ -36,17 +36,17 @@ func addFiles(drv graphdriver.Driver, layer string, seed int64) error {
|
|
|
}
|
|
|
defer drv.Put(layer)
|
|
|
|
|
|
- if err := driver.WriteFile(root, filepath.Join(root.Path(), "file-a"), randomContent(64, seed), 0755); err != nil {
|
|
|
+ if err := os.WriteFile(filepath.Join(root.Path(), "file-a"), randomContent(64, seed), 0755); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
- if err := root.MkdirAll(filepath.Join(root.Path(), "dir-b"), 0755); err != nil {
|
|
|
+ if err := os.MkdirAll(filepath.Join(root.Path(), "dir-b"), 0755); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
- if err := driver.WriteFile(root, filepath.Join(root.Path(), "dir-b", "file-b"), randomContent(128, seed+1), 0755); err != nil {
|
|
|
+ if err := os.WriteFile(filepath.Join(root.Path(), "dir-b", "file-b"), randomContent(128, seed+1), 0755); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
- return driver.WriteFile(root, filepath.Join(root.Path(), "file-c"), randomContent(128*128, seed+2), 0755)
|
|
|
+ return os.WriteFile(filepath.Join(root.Path(), "file-c"), randomContent(128*128, seed+2), 0755)
|
|
|
}
|
|
|
|
|
|
func checkFile(drv graphdriver.Driver, layer, filename string, content []byte) error {
|
|
@@ -56,7 +56,7 @@ func checkFile(drv graphdriver.Driver, layer, filename string, content []byte) e
|
|
|
}
|
|
|
defer drv.Put(layer)
|
|
|
|
|
|
- fileContent, err := driver.ReadFile(root, filepath.Join(root.Path(), filename))
|
|
|
+ fileContent, err := os.ReadFile(filepath.Join(root.Path(), filename))
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
@@ -75,7 +75,7 @@ func addFile(drv graphdriver.Driver, layer, filename string, content []byte) err
|
|
|
}
|
|
|
defer drv.Put(layer)
|
|
|
|
|
|
- return driver.WriteFile(root, filepath.Join(root.Path(), filename), content, 0755)
|
|
|
+ return os.WriteFile(filepath.Join(root.Path(), filename), content, 0755)
|
|
|
}
|
|
|
|
|
|
func addDirectory(drv graphdriver.Driver, layer, dir string) error {
|
|
@@ -85,7 +85,7 @@ func addDirectory(drv graphdriver.Driver, layer, dir string) error {
|
|
|
}
|
|
|
defer drv.Put(layer)
|
|
|
|
|
|
- return root.MkdirAll(filepath.Join(root.Path(), dir), 0755)
|
|
|
+ return os.MkdirAll(filepath.Join(root.Path(), dir), 0755)
|
|
|
}
|
|
|
|
|
|
func removeAll(drv graphdriver.Driver, layer string, names ...string) error {
|
|
@@ -96,7 +96,7 @@ func removeAll(drv graphdriver.Driver, layer string, names ...string) error {
|
|
|
defer drv.Put(layer)
|
|
|
|
|
|
for _, filename := range names {
|
|
|
- if err := root.RemoveAll(filepath.Join(root.Path(), filename)); err != nil {
|
|
|
+ if err := os.RemoveAll(filepath.Join(root.Path(), filename)); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
}
|
|
@@ -110,7 +110,7 @@ func checkFileRemoved(drv graphdriver.Driver, layer, filename string) error {
|
|
|
}
|
|
|
defer drv.Put(layer)
|
|
|
|
|
|
- if _, err := root.Stat(filepath.Join(root.Path(), filename)); err == nil {
|
|
|
+ if _, err := os.Stat(filepath.Join(root.Path(), filename)); err == nil {
|
|
|
return fmt.Errorf("file still exists: %s", filepath.Join(root.Path(), filename))
|
|
|
} else if !os.IsNotExist(err) {
|
|
|
return err
|
|
@@ -128,12 +128,12 @@ func addManyFiles(drv graphdriver.Driver, layer string, count int, seed int64) e
|
|
|
|
|
|
for i := 0; i < count; i += 100 {
|
|
|
dir := filepath.Join(root.Path(), fmt.Sprintf("directory-%d", i))
|
|
|
- if err := root.MkdirAll(dir, 0755); err != nil {
|
|
|
+ if err := os.MkdirAll(dir, 0755); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
for j := 0; i+j < count && j < 100; j++ {
|
|
|
file := filepath.Join(dir, fmt.Sprintf("file-%d", i+j))
|
|
|
- if err := driver.WriteFile(root, file, randomContent(64, seed+int64(i+j)), 0755); err != nil {
|
|
|
+ if err := os.WriteFile(file, randomContent(64, seed+int64(i+j)), 0755); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
}
|
|
@@ -152,7 +152,7 @@ func changeManyFiles(drv graphdriver.Driver, layer string, count int, seed int64
|
|
|
var changes []archive.Change
|
|
|
for i := 0; i < count; i += 100 {
|
|
|
archiveRoot := fmt.Sprintf("/directory-%d", i)
|
|
|
- if err := root.MkdirAll(filepath.Join(root.Path(), archiveRoot), 0755); err != nil {
|
|
|
+ if err := os.MkdirAll(filepath.Join(root.Path(), archiveRoot), 0755); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
for j := 0; i+j < count && j < 100; j++ {
|
|
@@ -168,21 +168,21 @@ func changeManyFiles(drv graphdriver.Driver, layer string, count int, seed int64
|
|
|
case 0:
|
|
|
change.Path = filepath.Join(archiveRoot, fmt.Sprintf("file-%d", i+j))
|
|
|
change.Kind = archive.ChangeModify
|
|
|
- if err := driver.WriteFile(root, filepath.Join(root.Path(), change.Path), randomContent(64, seed+int64(i+j)), 0755); err != nil {
|
|
|
+ if err := os.WriteFile(filepath.Join(root.Path(), change.Path), randomContent(64, seed+int64(i+j)), 0755); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
// Add file
|
|
|
case 1:
|
|
|
change.Path = filepath.Join(archiveRoot, fmt.Sprintf("file-%d-%d", seed, i+j))
|
|
|
change.Kind = archive.ChangeAdd
|
|
|
- if err := driver.WriteFile(root, filepath.Join(root.Path(), change.Path), randomContent(64, seed+int64(i+j)), 0755); err != nil {
|
|
|
+ if err := os.WriteFile(filepath.Join(root.Path(), change.Path), randomContent(64, seed+int64(i+j)), 0755); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
// Remove file
|
|
|
case 2:
|
|
|
change.Path = filepath.Join(archiveRoot, fmt.Sprintf("file-%d", i+j))
|
|
|
change.Kind = archive.ChangeDelete
|
|
|
- if err := root.Remove(filepath.Join(root.Path(), change.Path)); err != nil {
|
|
|
+ if err := os.Remove(filepath.Join(root.Path(), change.Path)); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
}
|
|
@@ -204,7 +204,7 @@ func checkManyFiles(drv graphdriver.Driver, layer string, count int, seed int64)
|
|
|
dir := filepath.Join(root.Path(), fmt.Sprintf("directory-%d", i))
|
|
|
for j := 0; i+j < count && j < 100; j++ {
|
|
|
file := filepath.Join(dir, fmt.Sprintf("file-%d", i+j))
|
|
|
- fileContent, err := driver.ReadFile(root, file)
|
|
|
+ fileContent, err := os.ReadFile(file)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
@@ -254,17 +254,17 @@ func addLayerFiles(drv graphdriver.Driver, layer, parent string, i int) error {
|
|
|
}
|
|
|
defer drv.Put(layer)
|
|
|
|
|
|
- if err := driver.WriteFile(root, filepath.Join(root.Path(), "top-id"), []byte(layer), 0755); err != nil {
|
|
|
+ if err := os.WriteFile(filepath.Join(root.Path(), "top-id"), []byte(layer), 0755); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
layerDir := filepath.Join(root.Path(), fmt.Sprintf("layer-%d", i))
|
|
|
- if err := root.MkdirAll(layerDir, 0755); err != nil {
|
|
|
+ if err := os.MkdirAll(layerDir, 0755); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
- if err := driver.WriteFile(root, filepath.Join(layerDir, "layer-id"), []byte(layer), 0755); err != nil {
|
|
|
+ if err := os.WriteFile(filepath.Join(layerDir, "layer-id"), []byte(layer), 0755); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
- return driver.WriteFile(root, filepath.Join(layerDir, "parent-id"), []byte(parent), 0755)
|
|
|
+ return os.WriteFile(filepath.Join(layerDir, "parent-id"), []byte(parent), 0755)
|
|
|
}
|
|
|
|
|
|
func addManyLayers(drv graphdriver.Driver, baseLayer string, count int) (string, error) {
|
|
@@ -291,7 +291,7 @@ func checkManyLayers(drv graphdriver.Driver, layer string, count int) error {
|
|
|
}
|
|
|
defer drv.Put(layer)
|
|
|
|
|
|
- layerIDBytes, err := driver.ReadFile(root, filepath.Join(root.Path(), "top-id"))
|
|
|
+ layerIDBytes, err := os.ReadFile(filepath.Join(root.Path(), "top-id"))
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
@@ -303,14 +303,14 @@ func checkManyLayers(drv graphdriver.Driver, layer string, count int) error {
|
|
|
for i := count; i > 0; i-- {
|
|
|
layerDir := filepath.Join(root.Path(), fmt.Sprintf("layer-%d", i))
|
|
|
|
|
|
- thisLayerIDBytes, err := driver.ReadFile(root, filepath.Join(layerDir, "layer-id"))
|
|
|
+ thisLayerIDBytes, err := os.ReadFile(filepath.Join(layerDir, "layer-id"))
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
if !bytes.Equal(thisLayerIDBytes, layerIDBytes) {
|
|
|
return fmt.Errorf("mismatched file content %v, expecting %v", thisLayerIDBytes, layerIDBytes)
|
|
|
}
|
|
|
- layerIDBytes, err = driver.ReadFile(root, filepath.Join(layerDir, "parent-id"))
|
|
|
+ layerIDBytes, err = os.ReadFile(filepath.Join(layerDir, "parent-id"))
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
@@ -318,11 +318,11 @@ func checkManyLayers(drv graphdriver.Driver, layer string, count int) error {
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-// readDir reads a directory just like driver.ReadDir()
|
|
|
+// readDir reads a directory just like os.ReadDir()
|
|
|
// then hides specific files (currently "lost+found")
|
|
|
// so the tests don't "see" it
|
|
|
-func readDir(r driver.Driver, dir string) ([]os.FileInfo, error) {
|
|
|
- a, err := driver.ReadDir(r, dir)
|
|
|
+func readDir(dir string) ([]fs.DirEntry, error) {
|
|
|
+ a, err := os.ReadDir(dir)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|