this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Revert "pkg/tool/file: add Mkdir, MkdirAll"

This reverts commit 23cc102dc038792ae8eec4d7010666b94fd3e77a.

Reason: CL 530736 accidentally submitted without running trybots (but
was +2-ed). If the tests passed this would perhaps be less of an issue
but unfortunately the Windows build fails.

Signed-off-by: Paul Jolly <paul@myitcv.io>
Change-Id: I1f6ba72ddb2fac369b97c7f73f3a5d31a6f2cbc9
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/531318
Unity-Result: CUEcueckoo <cueckoo@cuelang.org>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>

-152
-24
pkg/tool/file/doc.go
··· 66 66 // files: [...string] 67 67 // } 68 68 // 69 - // // Mkdir creates a directory at the specified path. 70 - // Mkdir: { 71 - // $id: "tool/file.Mkdir" 72 - // 73 - // // The directory path to create. 74 - // // If path is already a directory, Mkdir does nothing. 75 - // // If path already exists and is not a directory, Mkdir will return an error. 76 - // path: string 77 - // 78 - // // When true any necessary parents are created as well. 79 - // createParents: bool | *false 80 - // 81 - // // Directory mode and permission bits. 82 - // permissions: int | *0o755 83 - // } 84 - // 85 - // // MkdirAll creates a directory at the specified path along with any necessary 86 - // // parents. 87 - // // If path is already a directory, MkdirAll does nothing. 88 - // // If path already exists and is not a directory, MkdirAll will return an error. 89 - // MkdirAll: Mkdir & { 90 - // createParents: true 91 - // } 92 - // 93 69 package file
-24
pkg/tool/file/file.cue
··· 75 75 glob: !="" 76 76 files: [...string] 77 77 } 78 - 79 - // Mkdir creates a directory at the specified path. 80 - Mkdir: { 81 - $id: "tool/file.Mkdir" 82 - 83 - // The directory path to create. 84 - // If path is already a directory, Mkdir does nothing. 85 - // If path already exists and is not a directory, Mkdir will return an error. 86 - path: string 87 - 88 - // When true any necessary parents are created as well. 89 - createParents: bool | *false 90 - 91 - // Directory mode and permission bits. 92 - permissions: int | *0o755 93 - } 94 - 95 - // MkdirAll creates a directory at the specified path along with any necessary 96 - // parents. 97 - // If path is already a directory, MkdirAll does nothing. 98 - // If path already exists and is not a directory, MkdirAll will return an error. 99 - MkdirAll: Mkdir & { 100 - createParents: true 101 - }
-30
pkg/tool/file/file.go
··· 23 23 "path/filepath" 24 24 25 25 "cuelang.org/go/cue" 26 - "cuelang.org/go/cue/errors" 27 26 "cuelang.org/go/internal/task" 28 27 ) 29 28 ··· 32 31 task.Register("tool/file.Append", newAppendCmd) 33 32 task.Register("tool/file.Create", newCreateCmd) 34 33 task.Register("tool/file.Glob", newGlobCmd) 35 - task.Register("tool/file.Mkdir", newMkdirCmd) 36 34 } 37 35 38 36 func newReadCmd(v cue.Value) (task.Runner, error) { return &cmdRead{}, nil } 39 37 func newAppendCmd(v cue.Value) (task.Runner, error) { return &cmdAppend{}, nil } 40 38 func newCreateCmd(v cue.Value) (task.Runner, error) { return &cmdCreate{}, nil } 41 39 func newGlobCmd(v cue.Value) (task.Runner, error) { return &cmdGlob{}, nil } 42 - func newMkdirCmd(v cue.Value) (task.Runner, error) { return &cmdMkdir{}, nil } 43 40 44 41 type cmdRead struct{} 45 42 type cmdAppend struct{} 46 43 type cmdCreate struct{} 47 44 type cmdGlob struct{} 48 - type cmdMkdir struct{} 49 45 50 46 func (c *cmdRead) Run(ctx *task.Context) (res interface{}, err error) { 51 47 filename := ctx.String("filename") ··· 115 111 files := map[string]interface{}{"files": m} 116 112 return files, err 117 113 } 118 - 119 - func (c *cmdMkdir) Run(ctx *task.Context) (res interface{}, err error) { 120 - path := ctx.String("path") 121 - mode := ctx.Int64("permissions") 122 - createParents, _ := ctx.Lookup("createParents").Bool() 123 - 124 - if ctx.Err != nil { 125 - return nil, ctx.Err 126 - } 127 - 128 - if createParents { 129 - if err := os.MkdirAll(path, os.FileMode(mode)); err != nil { 130 - return nil, errors.Wrapf(err, ctx.Obj.Pos(), "failed to create directory") 131 - } 132 - } else { 133 - dir, err := os.Stat(path) 134 - if err == nil && dir.IsDir() { 135 - return nil, nil 136 - } 137 - if err := os.Mkdir(path, os.FileMode(mode)); err != nil { 138 - return nil, errors.Wrapf(err, ctx.Obj.Pos(), "failed to create directory") 139 - } 140 - } 141 - 142 - return nil, nil 143 - }
-65
pkg/tool/file/file_test.go
··· 137 137 t.Errorf("got %v; want %v", got, want) 138 138 } 139 139 } 140 - 141 - func TestMkdir(t *testing.T) { 142 - baseDir, err := os.MkdirTemp("", "") 143 - if err != nil { 144 - t.Fatal(err) 145 - } 146 - defer os.RemoveAll(baseDir) 147 - 148 - // simple dir creation 149 - d1 := filepath.Join(baseDir, "foo") 150 - v := parse(t, "tool/file.Mkdir", fmt.Sprintf(`{path: "%s"}`, d1)) 151 - _, err = (*cmdMkdir).Run(nil, &task.Context{Obj: v}) 152 - if err != nil { 153 - t.Fatal(err) 154 - } 155 - fi1, err := os.Stat(d1) 156 - if err != nil { 157 - t.Fatal(err) 158 - } 159 - if !fi1.IsDir() { 160 - t.Fatal("not a directory") 161 - } 162 - expectedMode1 := os.ModeDir | 0755 163 - if int(fi1.Mode()) != int(expectedMode1) { 164 - t.Fatal("wrong permissions", fi1.Mode()) 165 - } 166 - 167 - // dir already exists 168 - v = parse(t, "tool/file.Mkdir", fmt.Sprintf(`{path: "%s"}`, d1)) 169 - _, err = (*cmdMkdir).Run(nil, &task.Context{Obj: v}) 170 - if err != nil { 171 - t.Fatal(err) 172 - } 173 - 174 - // create parents 175 - // set permissions 176 - d2 := filepath.Join(baseDir, "bar/x") 177 - v = parse(t, "tool/file.MkdirAll", fmt.Sprintf(`{path: "%s", permissions: 0o700}`, d2)) 178 - _, err = (*cmdMkdir).Run(nil, &task.Context{Obj: v}) 179 - if err != nil { 180 - t.Fatal(err) 181 - } 182 - fi2, err := os.Stat(d2) 183 - if err != nil { 184 - t.Fatal(err) 185 - } 186 - if !fi2.IsDir() { 187 - t.Fatal("not a directory") 188 - } 189 - expectedMode2 := os.ModeDir | 0700 190 - if int(fi2.Mode()) != int(expectedMode2) { 191 - t.Fatal("wrong permissions", fi2.Mode()) 192 - } 193 - 194 - // file at same path 195 - f, err := ioutil.TempFile(baseDir, "") 196 - if err != nil { 197 - t.Fatal(err) 198 - } 199 - v = parse(t, "tool/file.Mkdir", fmt.Sprintf(`{path: "%s"}`, f.Name())) 200 - _, err = (*cmdMkdir).Run(nil, &task.Context{Obj: v}) 201 - if err == nil { 202 - t.Fatal("should not create directory at existing filepath") 203 - } 204 - }
-9
pkg/tool/file/pkg.go
··· 41 41 glob: !="" 42 42 files: [...string] 43 43 } 44 - Mkdir: { 45 - $id: "tool/file.Mkdir" 46 - path: string 47 - createParents: bool | *false 48 - permissions: int | *493 49 - } 50 - MkdirAll: Mkdir & { 51 - createParents: true 52 - } 53 44 }`, 54 45 }