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