Skip to content

Commit 0d96cbe

Browse files
bitfieldmvdan
authored andcommitted
Use 0o prefix for octal literals
1 parent 57a71e0 commit 0d96cbe

File tree

15 files changed

+52
-54
lines changed

15 files changed

+52
-54
lines changed

cache/cache.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ type Cache struct {
4646
// to share a cache directory (for example, if the directory were stored
4747
// in a network file system). File locking is notoriously unreliable in
4848
// network file systems and may not suffice to protect the cache.
49-
//
5049
func Open(dir string) (*Cache, error) {
5150
info, err := os.Stat(dir)
5251
if err != nil {
@@ -57,11 +56,11 @@ func Open(dir string) (*Cache, error) {
5756
}
5857
for i := 0; i < 256; i++ {
5958
name := filepath.Join(dir, fmt.Sprintf("%02x", i))
60-
if err := os.MkdirAll(name, 0777); err != nil {
59+
if err := os.MkdirAll(name, 0o777); err != nil {
6160
return nil, err
6261
}
6362
}
64-
f, err := os.OpenFile(filepath.Join(dir, "log.txt"), os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0666)
63+
f, err := os.OpenFile(filepath.Join(dir, "log.txt"), os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0o666)
6564
if err != nil {
6665
return nil, err
6766
}
@@ -283,7 +282,7 @@ func (c *Cache) Trim() {
283282
c.trimSubdir(subdir, cutoff)
284283
}
285284

286-
ioutil.WriteFile(filepath.Join(c.dir, "trim.txt"), []byte(fmt.Sprintf("%d", now.Unix())), 0666)
285+
ioutil.WriteFile(filepath.Join(c.dir, "trim.txt"), []byte(fmt.Sprintf("%d", now.Unix())), 0o666)
287286
}
288287

289288
// trimSubdir trims a single cache subdirectory.
@@ -337,7 +336,7 @@ func (c *Cache) putIndexEntry(id ActionID, out OutputID, size int64, allowVerify
337336
}
338337
}
339338
file := c.fileName(id, "a")
340-
if err := ioutil.WriteFile(file, entry, 0666); err != nil {
339+
if err := ioutil.WriteFile(file, entry, 0o666); err != nil {
341340
os.Remove(file)
342341
return err
343342
}
@@ -414,7 +413,7 @@ func (c *Cache) copyFile(file io.ReadSeeker, out OutputID, size int64) error {
414413
if err == nil && info.Size() > size { // shouldn't happen but fix in case
415414
mode |= os.O_TRUNC
416415
}
417-
f, err := os.OpenFile(name, mode, 0666)
416+
f, err := os.OpenFile(name, mode, 0o666)
418417
if err != nil {
419418
return err
420419
}

cache/cache_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func TestBasic(t *testing.T) {
3131
}
3232

3333
cdir := filepath.Join(dir, "c1")
34-
if err := os.Mkdir(cdir, 0777); err != nil {
34+
if err := os.Mkdir(cdir, 0o777); err != nil {
3535
t.Fatal(err)
3636
}
3737

cache/default.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ func initDefaultCache() {
3838
if dir == "off" {
3939
return
4040
}
41-
if err := os.MkdirAll(dir, 0777); err != nil {
41+
if err := os.MkdirAll(dir, 0o777); err != nil {
4242
if showWarnings {
4343
fmt.Fprintf(os.Stderr, "go: disabling cache (%s) due to initialization failure: %s\n", dir, err)
4444
}
4545
return
4646
}
4747
if _, err := os.Stat(filepath.Join(dir, "README")); err != nil {
4848
// Best effort.
49-
ioutil.WriteFile(filepath.Join(dir, "README"), []byte(cacheREADME), 0666)
49+
ioutil.WriteFile(filepath.Join(dir, "README"), []byte(cacheREADME), 0o666)
5050
}
5151

5252
c, err := Open(dir)

cmd/testscript/main.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ func mainerr() (retErr error) {
123123
}
124124

125125
runDir := filepath.Join(td, dirName)
126-
if err := os.Mkdir(runDir, 0777); err != nil {
126+
if err := os.Mkdir(runDir, 0o777); err != nil {
127127
return fmt.Errorf("failed to create a run directory within %v for %v: %v", td, renderFilename(filename), err)
128128
}
129129
if err := tr.run(runDir, filename); err != nil {
@@ -160,7 +160,7 @@ func (tr *testRunner) run(runDir, filename string) error {
160160

161161
mods := filepath.Join(runDir, goModProxyDir)
162162

163-
if err := os.MkdirAll(mods, 0777); err != nil {
163+
if err := os.MkdirAll(mods, 0o777); err != nil {
164164
return fmt.Errorf("failed to create goModProxy dir: %v", err)
165165
}
166166

@@ -198,7 +198,7 @@ func (tr *testRunner) run(runDir, filename string) error {
198198

199199
scriptFile := filepath.Join(runDir, "script.txtar")
200200

201-
if err := ioutil.WriteFile(scriptFile, txtar.Format(&script), 0666); err != nil {
201+
if err := ioutil.WriteFile(scriptFile, txtar.Format(&script), 0o666); err != nil {
202202
return fmt.Errorf("failed to write script for %v: %v", renderFilename(filename), err)
203203
}
204204

@@ -310,13 +310,12 @@ func (tr *testRunner) run(runDir, filename string) error {
310310
ar.Files[i] = newF
311311
}
312312
}
313-
if err := ioutil.WriteFile(filename, txtar.Format(ar), 0666); err != nil {
313+
if err := ioutil.WriteFile(filename, txtar.Format(ar), 0o666); err != nil {
314314
return fmt.Errorf("failed to write script back to %v for -update: %v", renderFilename(filename), err)
315315
}
316316
}
317317

318318
return nil
319-
320319
}
321320

322321
var (

cmd/txtar-addmod/addmod.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
// very large files into testdata/mod.
1616
//
1717
// It is acceptable to edit the archive afterward to remove or shorten files.
18-
//
1918
package main
2019

2120
import (
@@ -107,7 +106,7 @@ func main1() int {
107106

108107
exitCode := 0
109108
for _, arg := range modules {
110-
if err := ioutil.WriteFile(filepath.Join(tmpdir, "go.mod"), []byte("module m\n"), 0666); err != nil {
109+
if err := ioutil.WriteFile(filepath.Join(tmpdir, "go.mod"), []byte("module m\n"), 0o666); err != nil {
111110
fatalf("%v", err)
112111
}
113112
run(goCmd, "get", "-d", arg)
@@ -202,7 +201,7 @@ func main1() int {
202201
break
203202
}
204203
} else {
205-
if err := ioutil.WriteFile(filepath.Join(targetDir, modDir+".txtar"), data, 0666); err != nil {
204+
if err := ioutil.WriteFile(filepath.Join(targetDir, modDir+".txtar"), data, 0o666); err != nil {
206205
log.Printf("%s: %v", arg, err)
207206
exitCode = 1
208207
continue

cmd/txtar-x/extract_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func unquote(ts *testscript.TestScript, neg bool, args []string) {
3838
ts.Check(err)
3939
data = bytes.Replace(data, []byte("\n>"), []byte("\n"), -1)
4040
data = bytes.TrimPrefix(data, []byte(">"))
41-
err = ioutil.WriteFile(file, data, 0666)
41+
err = ioutil.WriteFile(file, data, 0o666)
4242
ts.Check(err)
4343
}
4444
}

dirhash/hash_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ func TestHashDir(t *testing.T) {
5252
t.Fatal(err)
5353
}
5454
defer os.RemoveAll(dir)
55-
if err := ioutil.WriteFile(filepath.Join(dir, "xyz"), []byte("data for xyz"), 0666); err != nil {
55+
if err := ioutil.WriteFile(filepath.Join(dir, "xyz"), []byte("data for xyz"), 0o666); err != nil {
5656
t.Fatal(err)
5757
}
58-
if err := ioutil.WriteFile(filepath.Join(dir, "abc"), []byte("data for abc"), 0666); err != nil {
58+
if err := ioutil.WriteFile(filepath.Join(dir, "abc"), []byte("data for abc"), 0o666); err != nil {
5959
t.Fatal(err)
6060
}
6161
want := htop("h1", fmt.Sprintf("%s %s\n%s %s\n", h("data for abc"), "prefix/abc", h("data for xyz"), "prefix/xyz"))
@@ -110,16 +110,16 @@ func TestDirFiles(t *testing.T) {
110110
t.Fatal(err)
111111
}
112112
defer os.RemoveAll(dir)
113-
if err := ioutil.WriteFile(filepath.Join(dir, "xyz"), []byte("data for xyz"), 0666); err != nil {
113+
if err := ioutil.WriteFile(filepath.Join(dir, "xyz"), []byte("data for xyz"), 0o666); err != nil {
114114
t.Fatal(err)
115115
}
116-
if err := ioutil.WriteFile(filepath.Join(dir, "abc"), []byte("data for abc"), 0666); err != nil {
116+
if err := ioutil.WriteFile(filepath.Join(dir, "abc"), []byte("data for abc"), 0o666); err != nil {
117117
t.Fatal(err)
118118
}
119-
if err := os.Mkdir(filepath.Join(dir, "subdir"), 0777); err != nil {
119+
if err := os.Mkdir(filepath.Join(dir, "subdir"), 0o777); err != nil {
120120
t.Fatal(err)
121121
}
122-
if err := ioutil.WriteFile(filepath.Join(dir, "subdir", "xyz"), []byte("data for subdir xyz"), 0666); err != nil {
122+
if err := ioutil.WriteFile(filepath.Join(dir, "subdir", "xyz"), []byte("data for subdir xyz"), 0o666); err != nil {
123123
t.Fatal(err)
124124
}
125125
prefix := "foo/[email protected]"

lockedfile/lockedfile.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,16 @@ func Open(name string) (*File, error) {
6464

6565
// Create is like os.Create, but returns a write-locked file.
6666
func Create(name string) (*File, error) {
67-
return OpenFile(name, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0666)
67+
return OpenFile(name, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0o666)
6868
}
6969

70-
// Edit creates the named file with mode 0666 (before umask),
70+
// Edit creates the named file with mode 0o666 (before umask),
7171
// but does not truncate existing contents.
7272
//
7373
// If Edit succeeds, methods on the returned File can be used for I/O.
7474
// The associated file descriptor has mode O_RDWR and the file is write-locked.
7575
func Edit(name string) (*File, error) {
76-
return OpenFile(name, os.O_RDWR|os.O_CREATE, 0666)
76+
return OpenFile(name, os.O_RDWR|os.O_CREATE, 0o666)
7777
}
7878

7979
// Close unlocks and closes the underlying file.

lockedfile/lockedfile_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ func TestCanLockExistingFile(t *testing.T) {
157157
defer remove()
158158
path := filepath.Join(dir, "existing.txt")
159159

160-
if err := ioutil.WriteFile(path, []byte("ok"), 0777); err != nil {
160+
if err := ioutil.WriteFile(path, []byte("ok"), 0o777); err != nil {
161161
t.Fatalf("ioutil.WriteFile: %v", err)
162162
}
163163

@@ -203,7 +203,7 @@ func TestSpuriousEDEADLK(t *testing.T) {
203203
}
204204
defer b.Close()
205205

206-
if err := ioutil.WriteFile(filepath.Join(dir, "locked"), []byte("ok"), 0666); err != nil {
206+
if err := ioutil.WriteFile(filepath.Join(dir, "locked"), []byte("ok"), 0o666); err != nil {
207207
t.Fatal(err)
208208
}
209209

lockedfile/mutex.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func (mu *Mutex) Lock() (unlock func(), err error) {
5252
// in the future, it should call OpenFile with O_RDONLY and will require the
5353
// files must be readable, so we should not let the caller make any
5454
// assumptions about Mutex working with write-only files.
55-
f, err := OpenFile(mu.Path, os.O_RDWR|os.O_CREATE, 0666)
55+
f, err := OpenFile(mu.Path, os.O_RDWR|os.O_CREATE, 0o666)
5656
if err != nil {
5757
return nil, err
5858
}

0 commit comments

Comments
 (0)