mirror of
https://github.com/github/codeql.git
synced 2025-12-17 01:03:14 +01:00
Stop using deprecate io/ioutil package
This commit is contained in:
@@ -3,7 +3,6 @@ package main
|
|||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
@@ -278,7 +277,7 @@ func fixGoVendorIssues(modMode ModMode, depMode DependencyInstallerMode, goDirec
|
|||||||
if depMode == GoGetWithModules {
|
if depMode == GoGetWithModules {
|
||||||
if !goDirectiveFound {
|
if !goDirectiveFound {
|
||||||
// if the go.mod does not contain a version line
|
// if the go.mod does not contain a version line
|
||||||
modulesTxt, err := ioutil.ReadFile("vendor/modules.txt")
|
modulesTxt, err := os.ReadFile("vendor/modules.txt")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("Failed to read vendor/modules.txt to check for mismatched Go version")
|
log.Println("Failed to read vendor/modules.txt to check for mismatched Go version")
|
||||||
} else if explicitRe := regexp.MustCompile("(?m)^## explicit$"); !explicitRe.Match(modulesTxt) {
|
} else if explicitRe := regexp.MustCompile("(?m)^## explicit$"); !explicitRe.Match(modulesTxt) {
|
||||||
@@ -365,7 +364,7 @@ type moveGopathInfo struct {
|
|||||||
func moveToTemporaryGopath(srcdir string, importpath string) moveGopathInfo {
|
func moveToTemporaryGopath(srcdir string, importpath string) moveGopathInfo {
|
||||||
// a temporary directory where everything is moved while the correct
|
// a temporary directory where everything is moved while the correct
|
||||||
// directory structure is created.
|
// directory structure is created.
|
||||||
scratch, err := ioutil.TempDir(srcdir, "scratch")
|
scratch, err := os.MkdirTemp(srcdir, "scratch")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Failed to create temporary directory %s in directory %s: %s\n",
|
log.Fatalf("Failed to create temporary directory %s in directory %s: %s\n",
|
||||||
scratch, srcdir, err.Error())
|
scratch, srcdir, err.Error())
|
||||||
@@ -431,7 +430,7 @@ func createPathTransformerFile(newdir string) *os.File {
|
|||||||
|
|
||||||
// set up SEMMLE_PATH_TRANSFORMER to ensure paths in the source archive and the snapshot
|
// set up SEMMLE_PATH_TRANSFORMER to ensure paths in the source archive and the snapshot
|
||||||
// match the original source location, not the location we moved it to
|
// match the original source location, not the location we moved it to
|
||||||
pt, err := ioutil.TempFile("", "path-transformer")
|
pt, err := os.CreateTemp("", "path-transformer")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Unable to create path transformer file: %s.", err.Error())
|
log.Fatalf("Unable to create path transformer file: %s.", err.Error())
|
||||||
}
|
}
|
||||||
@@ -506,7 +505,7 @@ func buildWithCustomCommands(inst string) {
|
|||||||
ext = ".sh"
|
ext = ".sh"
|
||||||
header = "#! /bin/bash\nset -xe +u\n"
|
header = "#! /bin/bash\nset -xe +u\n"
|
||||||
}
|
}
|
||||||
script, err := ioutil.TempFile("", "go-build-command-*"+ext)
|
script, err := os.CreateTemp("", "go-build-command-*"+ext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Unable to create temporary script holding custom build commands: %s\n", err.Error())
|
log.Fatalf("Unable to create temporary script holding custom build commands: %s\n", err.Error())
|
||||||
}
|
}
|
||||||
@@ -619,7 +618,7 @@ func installDependenciesAndBuild() {
|
|||||||
}
|
}
|
||||||
if depMode == GoGetWithModules {
|
if depMode == GoGetWithModules {
|
||||||
versionRe := regexp.MustCompile(`(?m)^go[ \t\r]+([0-9]+\.[0-9]+)$`)
|
versionRe := regexp.MustCompile(`(?m)^go[ \t\r]+([0-9]+\.[0-9]+)$`)
|
||||||
goMod, err := ioutil.ReadFile("go.mod")
|
goMod, err := os.ReadFile("go.mod")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("Failed to read go.mod to check for missing Go version")
|
log.Println("Failed to read go.mod to check for missing Go version")
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
@@ -22,7 +21,7 @@ func main() {
|
|||||||
buildSteps := os.Args[2]
|
buildSteps := os.Args[2]
|
||||||
|
|
||||||
haveRepo := false
|
haveRepo := false
|
||||||
content, err := ioutil.ReadFile(vars)
|
content, err := os.ReadFile(vars)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
@@ -34,7 +33,7 @@ func main() {
|
|||||||
additionalVars += "SEMMLE_REPO_URL=${repository}\n"
|
additionalVars += "SEMMLE_REPO_URL=${repository}\n"
|
||||||
}
|
}
|
||||||
content = append(content, []byte(additionalVars)...)
|
content = append(content, []byte(additionalVars)...)
|
||||||
err = ioutil.WriteFile(vars, content, 0644)
|
err = os.WriteFile(vars, content, 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
@@ -47,7 +46,7 @@ func main() {
|
|||||||
<build export="%s">${semmle_dist}/language-packs/go/tools/platform/${semmle_platform}/bin/go-autobuilder</build>
|
<build export="%s">${semmle_dist}/language-packs/go/tools/platform/${semmle_platform}/bin/go-autobuilder</build>
|
||||||
</autoupdate>
|
</autoupdate>
|
||||||
`, export))
|
`, export))
|
||||||
err = ioutil.WriteFile(buildSteps, content, 0644)
|
err = os.WriteFile(buildSteps, content, 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"go/scanner"
|
"go/scanner"
|
||||||
"go/token"
|
"go/token"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -20,7 +19,7 @@ func main() {
|
|||||||
defer csv.Flush()
|
defer csv.Flush()
|
||||||
|
|
||||||
for _, fileName := range flag.Args() {
|
for _, fileName := range flag.Args() {
|
||||||
src, err := ioutil.ReadFile(fileName)
|
src, err := os.ReadFile(fileName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Unable to read file %s.", fileName)
|
log.Fatalf("Unable to read file %s.", fileName)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import (
|
|||||||
"go/token"
|
"go/token"
|
||||||
"go/types"
|
"go/types"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@@ -1807,7 +1806,7 @@ func extractNumLines(tw *trap.Writer, fileName string, ast *ast.File) {
|
|||||||
|
|
||||||
// count lines of code by tokenizing
|
// count lines of code by tokenizing
|
||||||
linesOfCode := 0
|
linesOfCode := 0
|
||||||
src, err := ioutil.ReadFile(fileName)
|
src, err := os.ReadFile(fileName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Unable to read file %s.", fileName)
|
log.Fatalf("Unable to read file %s.", fileName)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,13 +2,14 @@ package extractor
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"golang.org/x/mod/modfile"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"golang.org/x/mod/modfile"
|
||||||
|
|
||||||
"github.com/github/codeql-go/extractor/dbscheme"
|
"github.com/github/codeql-go/extractor/dbscheme"
|
||||||
"github.com/github/codeql-go/extractor/srcarchive"
|
"github.com/github/codeql-go/extractor/srcarchive"
|
||||||
"github.com/github/codeql-go/extractor/trap"
|
"github.com/github/codeql-go/extractor/trap"
|
||||||
@@ -45,7 +46,7 @@ func (extraction *Extraction) extractGoMod(path string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to open go.mod file %s: %s", path, err.Error())
|
return fmt.Errorf("failed to open go.mod file %s: %s", path, err.Error())
|
||||||
}
|
}
|
||||||
data, err := ioutil.ReadAll(file)
|
data, err := io.ReadAll(file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to read go.mod file %s: %s", path, err.Error())
|
return fmt.Errorf("failed to read go.mod file %s: %s", path, err.Error())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
package srcarchive
|
package srcarchive
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func mkProjectLayout(projectLayoutSource string, t *testing.T) (*ProjectLayout, error) {
|
func mkProjectLayout(projectLayoutSource string, t *testing.T) (*ProjectLayout, error) {
|
||||||
pt, err := ioutil.TempFile("", "path-transformer")
|
pt, err := os.CreateTemp("", "path-transformer")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Unable to create temporary file for project layout: %s", err.Error())
|
t.Fatalf("Unable to create temporary file for project layout: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"go/ast"
|
"go/ast"
|
||||||
"go/types"
|
"go/types"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
@@ -51,7 +50,7 @@ func NewWriter(path string, pkg *packages.Package) (*Writer, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
tmpFile, err := ioutil.TempFile(trapFileDir, filepath.Base(trapFilePath))
|
tmpFile, err := os.CreateTemp(trapFileDir, filepath.Base(trapFilePath))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user