12 "github.com/fsouza/go-dockerclient/external/github.com/docker/docker/pkg/system"
15 func collectFileInfoForChanges(oldDir, newDir string) (*FileInfo, *FileInfo, error) {
17 oldRoot, newRoot *FileInfo
19 errs = make(chan error, 2)
22 oldRoot, err1 = collectFileInfo(oldDir)
26 newRoot, err2 = collectFileInfo(newDir)
30 // block until both routines have returned
31 for i := 0; i < 2; i++ {
32 if err := <-errs; err != nil {
37 return oldRoot, newRoot, nil
40 func collectFileInfo(sourceDir string) (*FileInfo, error) {
41 root := newRootFileInfo()
43 err := filepath.Walk(sourceDir, func(path string, f os.FileInfo, err error) error {
49 relPath, err := filepath.Rel(sourceDir, path)
54 // As this runs on the daemon side, file paths are OS specific.
55 relPath = filepath.Join(string(os.PathSeparator), relPath)
57 // See https://github.com/golang/go/issues/9168 - bug in filepath.Join.
58 // Temporary workaround. If the returned path starts with two backslashes,
59 // trim it down to a single backslash. Only relevant on Windows.
60 if runtime.GOOS == "windows" {
61 if strings.HasPrefix(relPath, `\\`) {
66 if relPath == string(os.PathSeparator) {
70 parent := root.LookUp(filepath.Dir(relPath))
72 return fmt.Errorf("collectFileInfo: Unexpectedly no parent for %s", relPath)
76 name: filepath.Base(relPath),
77 children: make(map[string]*FileInfo),
81 s, err := system.Lstat(path)
87 info.capability, _ = system.Lgetxattr(path, "security.capability")
89 parent.children[info.name] = info