Skip to content

Commit def5564

Browse files
authored
Remove deprecated functions (#608)
1 parent d3b6c4c commit def5564

File tree

18 files changed

+128
-141
lines changed

18 files changed

+128
-141
lines changed

fixtures/fake_dynatrace_api/main.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package main
33
import (
44
"encoding/json"
55
"fmt"
6-
"io/ioutil"
76
"log"
87
"net/http"
98
"os"
@@ -45,7 +44,7 @@ func main() {
4544
}
4645

4746
case "/dynatrace-env.sh", "/liboneagentproc.so", "/ruxitagentproc.conf":
48-
contents, err := ioutil.ReadFile(strings.TrimPrefix(req.URL.Path, "/"))
47+
contents, err := os.ReadFile(strings.TrimPrefix(req.URL.Path, "/"))
4948
if err != nil {
5049
w.WriteHeader(http.StatusInternalServerError)
5150
w.Write([]byte(err.Error()))
@@ -80,15 +79,14 @@ func main() {
8079
json.NewEncoder(w).Encode(payload)
8180

8281
case "/v1/deployment/installer/agent/processmoduleconfig":
83-
fakeConfig, err := ioutil.ReadFile("fake_config.json")
82+
fakeConfig, err := os.ReadFile("fake_config.json")
8483
if err != nil {
8584
w.WriteHeader(http.StatusInternalServerError)
8685
w.Write([]byte(err.Error()))
8786
return
8887
}
8988
w.Write(fakeConfig)
9089

91-
9290
default:
9391
w.WriteHeader(http.StatusNotFound)
9492
}

src/python/brats/brats_suite_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package brats_test
22

33
import (
44
"flag"
5-
"io/ioutil"
65
"os"
76
"path/filepath"
87
"strings"
@@ -68,7 +67,7 @@ func CopyBrats(version string) *cutlass.App {
6867
}
6968

7069
data := "python-" + version
71-
Expect(ioutil.WriteFile(filepath.Join(dir, "runtime.txt"), []byte(data), 0644)).To(Succeed())
70+
Expect(os.WriteFile(filepath.Join(dir, "runtime.txt"), []byte(data), 0644)).To(Succeed())
7271

7372
return cutlass.New(dir)
7473
}

src/python/conda/conda.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"bytes"
55
"fmt"
66
"io"
7-
"io/ioutil"
87
"os"
98
"path/filepath"
109
"strings"
@@ -77,7 +76,7 @@ func (c *Conda) Version() string {
7776
func (c *Conda) Install(version string) error {
7877
c.Log.BeginStep("Supplying conda")
7978
var installer string
80-
if installerDir, err := ioutil.TempDir("", "miniconda"); err != nil {
79+
if installerDir, err := os.MkdirTemp("", "miniconda"); err != nil {
8180
return err
8281
} else {
8382
installer = filepath.Join(installerDir, "miniconda.sh")
@@ -92,7 +91,7 @@ func (c *Conda) Install(version string) error {
9291
}
9392

9493
c.Log.BeginStep("Installing Miniconda")
95-
if err := c.Command.Execute("/", indentWriter(os.Stdout), ioutil.Discard, installer, "-b", "-p", c.condaHome()); err != nil {
94+
if err := c.Command.Execute("/", indentWriter(os.Stdout), io.Discard, installer, "-b", "-p", c.condaHome()); err != nil {
9695
return fmt.Errorf("Error installing miniconda: %v", err)
9796
}
9897

@@ -151,7 +150,7 @@ func (c *Conda) Warning() error {
151150
} else if !exists {
152151
return nil
153152
}
154-
if contents, err := ioutil.ReadFile(filepath.Join(c.Stager.BuildDir(), "environment.yml")); err != nil {
153+
if contents, err := os.ReadFile(filepath.Join(c.Stager.BuildDir(), "environment.yml")); err != nil {
155154
return err
156155
} else {
157156
if bytes.Contains(contents, []byte("python=")) {

src/python/conda/conda_test.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@ package conda_test
22

33
import (
44
"bytes"
5-
io "io"
6-
"io/ioutil"
5+
"io"
76
"os"
87
"path/filepath"
98

109
"github.com/cloudfoundry/python-buildpack/src/python/conda"
1110

1211
"github.com/cloudfoundry/libbuildpack"
1312
"github.com/cloudfoundry/libbuildpack/ansicleaner"
14-
gomock "github.com/golang/mock/gomock"
13+
"github.com/golang/mock/gomock"
1514
. "github.com/onsi/ginkgo"
1615
. "github.com/onsi/gomega"
1716
)
@@ -36,11 +35,11 @@ var _ = Describe("Conda", func() {
3635
)
3736

3837
BeforeEach(func() {
39-
buildDir, err = ioutil.TempDir("", "python-buildpack.build.")
38+
buildDir, err = os.MkdirTemp("", "python-buildpack.build.")
4039
Expect(err).To(BeNil())
41-
cacheDir, err = ioutil.TempDir("", "python-buildpack.cache.")
40+
cacheDir, err = os.MkdirTemp("", "python-buildpack.cache.")
4241
Expect(err).To(BeNil())
43-
depsDir, err = ioutil.TempDir("", "python-buildpack.deps.")
42+
depsDir, err = os.MkdirTemp("", "python-buildpack.deps.")
4443
Expect(err).To(BeNil())
4544
depsIdx = "13"
4645
depDir = filepath.Join(depsDir, depsIdx)
@@ -70,7 +69,7 @@ var _ = Describe("Conda", func() {
7069
Describe("Version", func() {
7170
Context("runtime.txt specifies python 3", func() {
7271
BeforeEach(func() {
73-
Expect(ioutil.WriteFile(filepath.Join(buildDir, "runtime.txt"), []byte("python-3.2.3"), 0644)).To(Succeed())
72+
Expect(os.WriteFile(filepath.Join(buildDir, "runtime.txt"), []byte("python-3.2.3"), 0644)).To(Succeed())
7473
})
7574

7675
It("returns 'miniconda3-py39'", func() {
@@ -88,7 +87,7 @@ var _ = Describe("Conda", func() {
8887
Describe("Install", func() {
8988
It("downloads and installs miniconda version", func() {
9089
mockInstaller.EXPECT().InstallOnlyVersion("Miniconda7", gomock.Any()).Do(func(_, path string) {
91-
Expect(ioutil.WriteFile(path, []byte{}, 0644)).To(Succeed())
90+
Expect(os.WriteFile(path, []byte{}, 0644)).To(Succeed())
9291
})
9392
mockCommand.EXPECT().Execute("/", gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any())
9493

@@ -97,7 +96,7 @@ var _ = Describe("Conda", func() {
9796

9897
It("make downloaded file executable", func() {
9998
mockInstaller.EXPECT().InstallOnlyVersion("Miniconda7", gomock.Any()).Do(func(_, path string) {
100-
Expect(ioutil.WriteFile(path, []byte{}, 0644)).To(Succeed())
99+
Expect(os.WriteFile(path, []byte{}, 0644)).To(Succeed())
101100
})
102101
mockCommand.EXPECT().Execute("/", gomock.Any(), gomock.Any(), gomock.Any(), "-b", "-p", filepath.Join(depDir, "conda")).Do(func(_ string, _, _ io.Writer, path string, _ ...string) {
103102
fi, err := os.Lstat(path)
@@ -111,7 +110,7 @@ var _ = Describe("Conda", func() {
111110
It("deletes installer", func() {
112111
var installerPath string
113112
mockInstaller.EXPECT().InstallOnlyVersion("Miniconda7", gomock.Any()).Do(func(_, path string) {
114-
Expect(ioutil.WriteFile(path, []byte{}, 0644)).To(Succeed())
113+
Expect(os.WriteFile(path, []byte{}, 0644)).To(Succeed())
115114
installerPath = path
116115
})
117116
mockCommand.EXPECT().Execute("/", gomock.Any(), gomock.Any(), gomock.Any(), "-b", "-p", filepath.Join(depDir, "conda")).Do(func(_ string, _, _ io.Writer, path string, _ ...string) {

src/python/finalize/cli/main.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package main
22

33
import (
44
"io"
5-
"io/ioutil"
65
"os"
76
"time"
87

@@ -15,7 +14,7 @@ import (
1514
)
1615

1716
func main() {
18-
logfile, err := ioutil.TempFile("", "cloudfoundry.python-buildpack.finalize")
17+
logfile, err := os.CreateTemp("", "cloudfoundry.python-buildpack.finalize")
1918
defer logfile.Close()
2019
if err != nil {
2120
logger := libbuildpack.NewLogger(os.Stdout)

src/python/finalize/finalize.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"bytes"
55
"fmt"
66
"io"
7-
"io/ioutil"
87
"os"
98
"path/filepath"
109
"regexp"
@@ -72,24 +71,24 @@ func Run(f *Finalizer) error {
7271

7372
func (f *Finalizer) HandleCollectstatic() error {
7473
if len(os.Getenv("DISABLE_COLLECTSTATIC")) > 0 {
75-
f.Log.Debug("DISABLE_COLLECTSTATIC > 0, skipping collectstatic")
74+
f.Log.Debug("DISABLE_COLLECTSTATIC > 0, skipping collectstatic")
7675
return nil
7776
}
7877

7978
exists, err := f.Requirements.FindAnyPackage(f.Stager.BuildDir(), "django", "Django")
8079
if err != nil {
81-
f.Log.Debug("Error during FindAnyPackage, skipping collectstatic")
80+
f.Log.Debug("Error during FindAnyPackage, skipping collectstatic")
8281
return err
8382
}
8483

8584
if !exists {
86-
f.Log.Debug("Django not in requirements, skipping collectstatic")
85+
f.Log.Debug("Django not in requirements, skipping collectstatic")
8786
return nil
8887
}
8988

9089
managePyPath, err := f.ManagePyFinder.FindManagePy(f.Stager.BuildDir())
9190
if err != nil {
92-
f.Log.Debug("Error finding manage.py, skipping collectstatic")
91+
f.Log.Debug("Error finding manage.py, skipping collectstatic")
9392
return err
9493
}
9594

@@ -135,14 +134,14 @@ func (f *Finalizer) ReplaceDepsDirWithLiteral() error {
135134
for _, dir := range dirs {
136135
if err := filepath.Walk(dir, func(path string, _ os.FileInfo, _ error) error {
137136
if strings.HasSuffix(path, ".pth") {
138-
fileContents, err := ioutil.ReadFile(path)
137+
fileContents, err := os.ReadFile(path)
139138
if err != nil {
140139
return err
141140
}
142141

143142
fileContents = []byte(strings.Replace(string(fileContents), f.Stager.DepDir(), "DOLLAR_DEPS_DIR/"+f.Stager.DepsIdx(), -1))
144143

145-
if err := ioutil.WriteFile(path, fileContents, 0644); err != nil {
144+
if err := os.WriteFile(path, fileContents, 0644); err != nil {
146145
return err
147146
}
148147
}

src/python/finalize/finalize_test.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package finalize_test
33
import (
44
"bytes"
55
"fmt"
6-
"io/ioutil"
76
"os"
87
"os/exec"
98
"path"
@@ -37,10 +36,10 @@ var _ = Describe("Finalize", func() {
3736
)
3837

3938
BeforeEach(func() {
40-
buildDir, err = ioutil.TempDir("", "python-buildpack.build.")
39+
buildDir, err = os.MkdirTemp("", "python-buildpack.build.")
4140
Expect(err).To(BeNil())
4241

43-
depsDir, err = ioutil.TempDir("", "python-buildpack.deps.")
42+
depsDir, err = os.MkdirTemp("", "python-buildpack.deps.")
4443
Expect(err).To(BeNil())
4544

4645
depsIdx = "9"
@@ -135,15 +134,15 @@ var _ = Describe("Finalize", func() {
135134
var file string
136135
runSubjectAndReadContents := func() string {
137136
Expect(finalizer.ReplaceDepsDirWithLiteral()).To(Succeed())
138-
contents, err := ioutil.ReadFile(file)
137+
contents, err := os.ReadFile(file)
139138
Expect(err).ToNot(HaveOccurred())
140139
return string(contents)
141140
}
142141
Context("file at site-packages root", func() {
143142
BeforeEach(func() {
144143
file = filepath.Join(depsDir, depsIdx, "python", "lib", "python2.7", "site-packages", "easy-install.pth")
145144
Expect(os.MkdirAll(path.Dir(file), 0755)).To(Succeed())
146-
Expect(ioutil.WriteFile(file, []byte("./pip-9.0.1-py2.7.egg\n"+depsDir+"/9/src/regcore\n"), 0644)).To(Succeed())
145+
Expect(os.WriteFile(file, []byte("./pip-9.0.1-py2.7.egg\n"+depsDir+"/9/src/regcore\n"), 0644)).To(Succeed())
147146
})
148147
It("Converts DepsDir value to '$DEPS_DIR' string", func() {
149148
Expect(runSubjectAndReadContents()).To(Equal("./pip-9.0.1-py2.7.egg\nDOLLAR_DEPS_DIR/9/src/regcore\n"))
@@ -153,7 +152,7 @@ var _ = Describe("Finalize", func() {
153152
BeforeEach(func() {
154153
file = filepath.Join(depsDir, depsIdx, "python", "lib", "python3.2", "site-packages", "something", "extra", "fred.pth")
155154
Expect(os.MkdirAll(path.Dir(file), 0755)).To(Succeed())
156-
Expect(ioutil.WriteFile(file, []byte(depsDir+"/9/src/bing\n./pip-9.0.1-py2.7.egg\n"+depsDir+"/9/src/regcore\n"), 0644)).To(Succeed())
155+
Expect(os.WriteFile(file, []byte(depsDir+"/9/src/bing\n./pip-9.0.1-py2.7.egg\n"+depsDir+"/9/src/regcore\n"), 0644)).To(Succeed())
157156
})
158157
It("Converts DepsDir value to '$DEPS_DIR' string", func() {
159158
Expect(runSubjectAndReadContents()).To(Equal("DOLLAR_DEPS_DIR/9/src/bing\n./pip-9.0.1-py2.7.egg\nDOLLAR_DEPS_DIR/9/src/regcore\n"))
@@ -167,7 +166,7 @@ var _ = Describe("Finalize", func() {
167166
BeforeEach(func() {
168167
file = filepath.Join(depsDir, depsIdx, "python", "lib", "python2.7", "site-packages", "easy-install.pth")
169168
Expect(os.MkdirAll(path.Dir(file), 0755)).To(Succeed())
170-
Expect(ioutil.WriteFile(file, []byte("./pip-9.0.1-py2.7.egg\nDOLLAR_DEPS_DIR/9/src/regcore\n"), 0644)).To(Succeed())
169+
Expect(os.WriteFile(file, []byte("./pip-9.0.1-py2.7.egg\nDOLLAR_DEPS_DIR/9/src/regcore\n"), 0644)).To(Succeed())
171170
})
172171
It("At runtime, converts the contents to the runtime depsDir", func() {
173172
Expect(finalizer.ReplaceLiteralWithDepsDirAtRuntime()).To(Succeed())
@@ -176,7 +175,7 @@ var _ = Describe("Finalize", func() {
176175
cmd.Env = append(os.Environ(), "DEPS_DIR="+depsDir)
177176
Expect(cmd.Run()).To(Succeed())
178177

179-
contents, err := ioutil.ReadFile(file)
178+
contents, err := os.ReadFile(file)
180179
Expect(err).ToNot(HaveOccurred())
181180
Expect(string(contents)).To(Equal("./pip-9.0.1-py2.7.egg\n" + depsDir + "/9/src/regcore\n"))
182181
})

src/python/hooks/appdynamics.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ import (
55
"errors"
66
"fmt"
77
"io"
8-
"io/ioutil"
98
"os"
109
"path/filepath"
1110
"sort"
1211
"strings"
1312

14-
"github.com/cloudfoundry/libbuildpack"
1513
"regexp"
14+
15+
"github.com/cloudfoundry/libbuildpack"
1616
)
1717

1818
type Command interface {
@@ -73,7 +73,7 @@ func (h AppdynamicsHook) GenerateStartUpCommand(startCommand string) (string, er
7373
}
7474

7575
func (h AppdynamicsHook) RewriteProcFile(procFilePath string) error {
76-
startCommand, err := ioutil.ReadFile(procFilePath)
76+
startCommand, err := os.ReadFile(procFilePath)
7777
if err != nil {
7878
return fmt.Errorf("Error reading file %s: %v", procFilePath, err)
7979
}
@@ -82,7 +82,7 @@ func (h AppdynamicsHook) RewriteProcFile(procFilePath string) error {
8282
return err
8383
}
8484

85-
if err := ioutil.WriteFile(procFilePath, []byte(newCommand), 0666); err != nil {
85+
if err := os.WriteFile(procFilePath, []byte(newCommand), 0666); err != nil {
8686
return fmt.Errorf("Error writing file %s: %v", procFilePath, err)
8787
}
8888
return nil
@@ -113,7 +113,7 @@ func (h AppdynamicsHook) RewriteRequirementsFile(stager *libbuildpack.Stager) er
113113
if _, err = f.WriteString(packageName); err != nil {
114114
panic(err)
115115
}
116-
fileContents, _ := ioutil.ReadFile(f.Name())
116+
fileContents, _ := os.ReadFile(f.Name())
117117
h.Log.Info(string(fileContents))
118118

119119
return nil
@@ -128,7 +128,7 @@ func (h AppdynamicsHook) RewriteProcFileWithAppdynamics(stager *libbuildpack.Sta
128128
if err := h.RewriteProcFile(file); err != nil {
129129
return err
130130
}
131-
fileContents, _ := ioutil.ReadFile(file)
131+
fileContents, _ := os.ReadFile(file)
132132
h.Log.Info(string(fileContents))
133133
} else {
134134
h.Log.Info("Cannot find Procfile, skipping this step!")

0 commit comments

Comments
 (0)