Fixing 'docker save' on Windows.

Save was failing file integrity checksums due to bugs in both
Windows and Docker. This commit includes fixes to file time handling
in tarexport and system.chtimes that are necessary along with
the Windows platform fixes to correctly support save. With this
change, sysfile_backups for windowsfilter driver are no longer
needed, so that code is removed.

Signed-off-by: Stefan J. Wernli <swernli@microsoft.com>
This commit is contained in:
Stefan J. Wernli 2016-02-08 15:40:12 -08:00
parent a830282265
commit 24854e692c
5 changed files with 52 additions and 4 deletions

View file

@ -8,6 +8,8 @@ import (
"sort" "sort"
"testing" "testing"
"time" "time"
"github.com/docker/docker/pkg/system"
) )
func max(x, y int) int { func max(x, y int) int {
@ -87,7 +89,7 @@ func createSampleDir(t *testing.T, root string) {
if info.filetype != Symlink { if info.filetype != Symlink {
// Set a consistent ctime, atime for all files and dirs // Set a consistent ctime, atime for all files and dirs
if err := os.Chtimes(p, now, now); err != nil { if err := system.Chtimes(p, now, now); err != nil {
t.Fatal(err) t.Fatal(err)
} }
} }
@ -289,7 +291,7 @@ func mutateSampleDir(t *testing.T, root string) {
} }
// Touch file // Touch file
if err := os.Chtimes(path.Join(root, "file4"), time.Now().Add(time.Second), time.Now().Add(time.Second)); err != nil { if err := system.Chtimes(path.Join(root, "file4"), time.Now().Add(time.Second), time.Now().Add(time.Second)); err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -333,7 +335,7 @@ func mutateSampleDir(t *testing.T, root string) {
} }
// Touch dir // Touch dir
if err := os.Chtimes(path.Join(root, "dir3"), time.Now().Add(time.Second), time.Now().Add(time.Second)); err != nil { if err := system.Chtimes(path.Join(root, "dir3"), time.Now().Add(time.Second), time.Now().Add(time.Second)); err != nil {
t.Fatal(err) t.Fatal(err)
} }
} }

View file

@ -43,5 +43,10 @@ func Chtimes(name string, atime time.Time, mtime time.Time) error {
return err return err
} }
// Take platform specific action for setting create time.
if err := setCTime(name, mtime); err != nil {
return err
}
return nil return nil
} }

14
system/chtimes_unix.go Normal file
View file

@ -0,0 +1,14 @@
// +build !windows
package system
import (
"time"
)
//setCTime will set the create time on a file. On Unix, the create
//time is updated as a side effect of setting the modified time, so
//no action is required.
func setCTime(path string, ctime time.Time) error {
return nil
}

View file

@ -1,4 +1,4 @@
// +build linux freebsd // +build !windows
package system package system

27
system/chtimes_windows.go Normal file
View file

@ -0,0 +1,27 @@
// +build windows
package system
import (
"syscall"
"time"
)
//setCTime will set the create time on a file. On Windows, this requires
//calling SetFileTime and explicitly including the create time.
func setCTime(path string, ctime time.Time) error {
ctimespec := syscall.NsecToTimespec(ctime.UnixNano())
pathp, e := syscall.UTF16PtrFromString(path)
if e != nil {
return e
}
h, e := syscall.CreateFile(pathp,
syscall.FILE_WRITE_ATTRIBUTES, syscall.FILE_SHARE_WRITE, nil,
syscall.OPEN_EXISTING, syscall.FILE_FLAG_BACKUP_SEMANTICS, 0)
if e != nil {
return e
}
defer syscall.Close(h)
c := syscall.NsecToFiletime(syscall.TimespecToNsec(ctimespec))
return syscall.SetFileTime(h, &c, nil, nil)
}