remotefs_filedriver.go 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. // +build windows
  2. package lcow
  3. import (
  4. "bytes"
  5. "encoding/json"
  6. "os"
  7. "strconv"
  8. "github.com/Microsoft/opengcs/service/gcsutils/remotefs"
  9. "github.com/containerd/continuity/driver"
  10. "github.com/sirupsen/logrus"
  11. )
  12. var _ driver.Driver = &lcowfs{}
  13. func (l *lcowfs) Readlink(p string) (string, error) {
  14. logrus.Debugf("removefs.readlink args: %s", p)
  15. result := &bytes.Buffer{}
  16. if err := l.runRemoteFSProcess(nil, result, remotefs.ReadlinkCmd, p); err != nil {
  17. return "", err
  18. }
  19. return result.String(), nil
  20. }
  21. func (l *lcowfs) Mkdir(path string, mode os.FileMode) error {
  22. return l.mkdir(path, mode, remotefs.MkdirCmd)
  23. }
  24. func (l *lcowfs) MkdirAll(path string, mode os.FileMode) error {
  25. return l.mkdir(path, mode, remotefs.MkdirAllCmd)
  26. }
  27. func (l *lcowfs) mkdir(path string, mode os.FileMode, cmd string) error {
  28. modeStr := strconv.FormatUint(uint64(mode), 8)
  29. logrus.Debugf("remotefs.%s args: %s %s", cmd, path, modeStr)
  30. return l.runRemoteFSProcess(nil, nil, cmd, path, modeStr)
  31. }
  32. func (l *lcowfs) Remove(path string) error {
  33. return l.remove(path, remotefs.RemoveCmd)
  34. }
  35. func (l *lcowfs) RemoveAll(path string) error {
  36. return l.remove(path, remotefs.RemoveAllCmd)
  37. }
  38. func (l *lcowfs) remove(path string, cmd string) error {
  39. logrus.Debugf("remotefs.%s args: %s", cmd, path)
  40. return l.runRemoteFSProcess(nil, nil, cmd, path)
  41. }
  42. func (l *lcowfs) Link(oldname, newname string) error {
  43. return l.link(oldname, newname, remotefs.LinkCmd)
  44. }
  45. func (l *lcowfs) Symlink(oldname, newname string) error {
  46. return l.link(oldname, newname, remotefs.SymlinkCmd)
  47. }
  48. func (l *lcowfs) link(oldname, newname, cmd string) error {
  49. logrus.Debugf("remotefs.%s args: %s %s", cmd, oldname, newname)
  50. return l.runRemoteFSProcess(nil, nil, cmd, oldname, newname)
  51. }
  52. func (l *lcowfs) Lchown(name string, uid, gid int64) error {
  53. uidStr := strconv.FormatInt(uid, 10)
  54. gidStr := strconv.FormatInt(gid, 10)
  55. logrus.Debugf("remotefs.lchown args: %s %s %s", name, uidStr, gidStr)
  56. return l.runRemoteFSProcess(nil, nil, remotefs.LchownCmd, name, uidStr, gidStr)
  57. }
  58. // Lchmod changes the mode of an file not following symlinks.
  59. func (l *lcowfs) Lchmod(path string, mode os.FileMode) error {
  60. modeStr := strconv.FormatUint(uint64(mode), 8)
  61. logrus.Debugf("remotefs.lchmod args: %s %s", path, modeStr)
  62. return l.runRemoteFSProcess(nil, nil, remotefs.LchmodCmd, path, modeStr)
  63. }
  64. func (l *lcowfs) Mknod(path string, mode os.FileMode, major, minor int) error {
  65. modeStr := strconv.FormatUint(uint64(mode), 8)
  66. majorStr := strconv.FormatUint(uint64(major), 10)
  67. minorStr := strconv.FormatUint(uint64(minor), 10)
  68. logrus.Debugf("remotefs.mknod args: %s %s %s %s", path, modeStr, majorStr, minorStr)
  69. return l.runRemoteFSProcess(nil, nil, remotefs.MknodCmd, path, modeStr, majorStr, minorStr)
  70. }
  71. func (l *lcowfs) Mkfifo(path string, mode os.FileMode) error {
  72. modeStr := strconv.FormatUint(uint64(mode), 8)
  73. logrus.Debugf("remotefs.mkfifo args: %s %s", path, modeStr)
  74. return l.runRemoteFSProcess(nil, nil, remotefs.MkfifoCmd, path, modeStr)
  75. }
  76. func (l *lcowfs) Stat(p string) (os.FileInfo, error) {
  77. return l.stat(p, remotefs.StatCmd)
  78. }
  79. func (l *lcowfs) Lstat(p string) (os.FileInfo, error) {
  80. return l.stat(p, remotefs.LstatCmd)
  81. }
  82. func (l *lcowfs) stat(path string, cmd string) (os.FileInfo, error) {
  83. logrus.Debugf("remotefs.stat inputs: %s %s", cmd, path)
  84. output := &bytes.Buffer{}
  85. err := l.runRemoteFSProcess(nil, output, cmd, path)
  86. if err != nil {
  87. return nil, err
  88. }
  89. var fi remotefs.FileInfo
  90. if err := json.Unmarshal(output.Bytes(), &fi); err != nil {
  91. return nil, err
  92. }
  93. logrus.Debugf("remotefs.stat success. got: %v\n", fi)
  94. return &fi, nil
  95. }