Skip to content

Commit

Permalink
Fix generation of code depending on io/ioutil.
Browse files Browse the repository at this point in the history
  • Loading branch information
armfazh committed Aug 9, 2022
1 parent f5aa847 commit 861cf84
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
18 changes: 9 additions & 9 deletions pke/kyber/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func generateParamsFiles() {
if offset == -1 {
panic("Missing template warning in params.templ.go")
}
err = io.WriteFile(mode.Pkg()+"/internal/params.go",
err = os.WriteFile(mode.Pkg()+"/internal/params.go",
[]byte(res[offset:]), 0o644)
if err != nil {
panic(err)
Expand All @@ -120,7 +120,7 @@ func generatePackageFiles() {
if offset == -1 {
panic("Missing template warning in pkg.templ.go")
}
err = io.WriteFile(mode.Pkg()+"/kyber.go", []byte(res[offset:]), 0o644)
err = os.WriteFile(mode.Pkg()+"/kyber.go", []byte(res[offset:]), 0o644)
if err != nil {
panic(err)
}
Expand All @@ -136,7 +136,7 @@ func generateSourceFiles() {
return x == "params.go" || x == "params_test.go"
}

fs, err := io.ReadDir("kyber512/internal")
fs, err := os.ReadDir("kyber512/internal")
if err != nil {
panic(err)
}
Expand All @@ -147,7 +147,7 @@ func generateSourceFiles() {
if ignored(name) {
continue
}
files[name], err = io.ReadFile(path.Join("kyber512/internal", name))
files[name], err = os.ReadFile(path.Join("kyber512/internal", name))
if err != nil {
panic(err)
}
Expand All @@ -159,7 +159,7 @@ func generateSourceFiles() {
continue
}

fs, err = io.ReadDir(path.Join(mode.Pkg(), "internal"))
fs, err = os.ReadDir(path.Join(mode.Pkg(), "internal"))
for _, f := range fs {
name := f.Name()
fn := path.Join(mode.Pkg(), "internal", name)
Expand All @@ -174,10 +174,10 @@ func generateSourceFiles() {
panic(err)
}
}
if f.Mode().IsDir() {
if f.IsDir() {
panic(fmt.Sprintf("%s: is a directory", fn))
}
if f.Mode()&os.ModeSymlink != 0 {
if f.Type()&os.ModeSymlink != 0 {
fmt.Printf("Removing symlink: %s\n", fn)
err = os.Remove(fn)
if err != nil {
Expand All @@ -193,14 +193,14 @@ func generateSourceFiles() {
name,
string(expected),
))
got, err := io.ReadFile(fn)
got, err := os.ReadFile(fn)
if err == nil {
if bytes.Equal(got, expected) {
continue
}
}
fmt.Printf("Updating %s\n", fn)
err = io.WriteFile(fn, expected, 0o644)
err = os.WriteFile(fn, expected, 0o644)
if err != nil {
panic(err)
}
Expand Down
20 changes: 10 additions & 10 deletions sign/dilithium/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func generateParamsFiles() {
if offset == -1 {
panic("Missing template warning in params.templ.go")
}
err = io.WriteFile(mode.Pkg()+"/internal/params.go",
err = os.WriteFile(mode.Pkg()+"/internal/params.go",
[]byte(res[offset:]), 0o644)
if err != nil {
panic(err)
Expand All @@ -180,7 +180,7 @@ func generateModeToplevelFiles() {
if offset == -1 {
panic("Missing template warning in mode.templ.go")
}
err = io.WriteFile(mode.Pkg()+".go", []byte(res[offset:]), 0o644)
err = os.WriteFile(mode.Pkg()+".go", []byte(res[offset:]), 0o644)
if err != nil {
panic(err)
}
Expand All @@ -206,7 +206,7 @@ func generateModePackageFiles() {
if offset == -1 {
panic("Missing template warning in modePkg.templ.go")
}
err = io.WriteFile(mode.Pkg()+"/dilithium.go", []byte(res[offset:]), 0o644)
err = os.WriteFile(mode.Pkg()+"/dilithium.go", []byte(res[offset:]), 0o644)
if err != nil {
panic(err)
}
Expand All @@ -223,7 +223,7 @@ func generateSourceFiles() {
strings.HasSuffix(x, ".swp")
}

fs, err := io.ReadDir("mode3/internal")
fs, err := os.ReadDir("mode3/internal")
if err != nil {
panic(err)
}
Expand All @@ -234,7 +234,7 @@ func generateSourceFiles() {
if ignored(name) {
continue
}
files[name], err = io.ReadFile(path.Join("mode3/internal", name))
files[name], err = os.ReadFile(path.Join("mode3/internal", name))
if err != nil {
panic(err)
}
Expand All @@ -246,7 +246,7 @@ func generateSourceFiles() {
continue
}

fs, err = io.ReadDir(path.Join(mode.Pkg(), "internal"))
fs, err = os.ReadDir(path.Join(mode.Pkg(), "internal"))
for _, f := range fs {
name := f.Name()
fn := path.Join(mode.Pkg(), "internal", name)
Expand All @@ -261,10 +261,10 @@ func generateSourceFiles() {
panic(err)
}
}
if f.Mode().IsDir() {
if f.IsDir() {
panic(fmt.Sprintf("%s: is a directory", fn))
}
if f.Mode()&os.ModeSymlink != 0 {
if f.Type()&os.ModeSymlink != 0 {
fmt.Printf("Removing symlink: %s\n", fn)
err = os.Remove(fn)
if err != nil {
Expand All @@ -280,14 +280,14 @@ func generateSourceFiles() {
name,
string(expected),
))
got, err := io.ReadFile(fn)
got, err := os.ReadFile(fn)
if err == nil {
if bytes.Equal(got, expected) {
continue
}
}
fmt.Printf("Updating %s\n", fn)
err = io.WriteFile(fn, expected, 0o644)
err = os.WriteFile(fn, expected, 0o644)
if err != nil {
panic(err)
}
Expand Down

0 comments on commit 861cf84

Please sign in to comment.