archive_windows.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // +build windows
  2. package archive
  3. import (
  4. "archive/tar"
  5. "fmt"
  6. "os"
  7. "path/filepath"
  8. "strings"
  9. "github.com/docker/docker/pkg/longpath"
  10. )
  11. // fixVolumePathPrefix does platform specific processing to ensure that if
  12. // the path being passed in is not in a volume path format, convert it to one.
  13. func fixVolumePathPrefix(srcPath string) string {
  14. return longpath.AddPrefix(srcPath)
  15. }
  16. // getWalkRoot calculates the root path when performing a TarWithOptions.
  17. // We use a separate function as this is platform specific.
  18. func getWalkRoot(srcPath string, include string) string {
  19. return filepath.Join(srcPath, include)
  20. }
  21. // CanonicalTarNameForPath returns platform-specific filepath
  22. // to canonical posix-style path for tar archival. p is relative
  23. // path.
  24. func CanonicalTarNameForPath(p string) (string, error) {
  25. // windows: convert windows style relative path with backslashes
  26. // into forward slashes. Since windows does not allow '/' or '\'
  27. // in file names, it is mostly safe to replace however we must
  28. // check just in case
  29. if strings.Contains(p, "/") {
  30. return "", fmt.Errorf("Windows path contains forward slash: %s", p)
  31. }
  32. return strings.Replace(p, string(os.PathSeparator), "/", -1), nil
  33. }
  34. // chmodTarEntry is used to adjust the file permissions used in tar header based
  35. // on the platform the archival is done.
  36. func chmodTarEntry(perm os.FileMode) os.FileMode {
  37. //perm &= 0755 // this 0-ed out tar flags (like link, regular file, directory marker etc.)
  38. permPart := perm & os.ModePerm
  39. noPermPart := perm &^ os.ModePerm
  40. // Add the x bit: make everything +x from windows
  41. permPart |= 0111
  42. permPart &= 0755
  43. return noPermPart | permPart
  44. }
  45. func setHeaderForSpecialDevice(hdr *tar.Header, name string, stat interface{}) (err error) {
  46. // do nothing. no notion of Rdev, Nlink in stat on Windows
  47. return
  48. }
  49. func getInodeFromStat(stat interface{}) (inode uint64, err error) {
  50. // do nothing. no notion of Inode in stat on Windows
  51. return
  52. }
  53. // handleTarTypeBlockCharFifo is an OS-specific helper function used by
  54. // createTarFile to handle the following types of header: Block; Char; Fifo
  55. func handleTarTypeBlockCharFifo(hdr *tar.Header, path string) error {
  56. return nil
  57. }
  58. func handleLChmod(hdr *tar.Header, path string, hdrInfo os.FileInfo) error {
  59. return nil
  60. }
  61. func getFileUIDGID(stat interface{}) (int, int, error) {
  62. // no notion of file ownership mapping yet on Windows
  63. return 0, 0, nil
  64. }