Skip to content

Commit

Permalink
Remove deprecated functions (#608)
Browse files Browse the repository at this point in the history
  • Loading branch information
brayanhenao authored Sep 24, 2022
1 parent d3b6c4c commit def5564
Show file tree
Hide file tree
Showing 18 changed files with 128 additions and 141 deletions.
6 changes: 2 additions & 4 deletions fixtures/fake_dynatrace_api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
Expand Down Expand Up @@ -45,7 +44,7 @@ func main() {
}

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

case "/v1/deployment/installer/agent/processmoduleconfig":
fakeConfig, err := ioutil.ReadFile("fake_config.json")
fakeConfig, err := os.ReadFile("fake_config.json")
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(err.Error()))
return
}
w.Write(fakeConfig)


default:
w.WriteHeader(http.StatusNotFound)
}
Expand Down
3 changes: 1 addition & 2 deletions src/python/brats/brats_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package brats_test

import (
"flag"
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -68,7 +67,7 @@ func CopyBrats(version string) *cutlass.App {
}

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

return cutlass.New(dir)
}
Expand Down
7 changes: 3 additions & 4 deletions src/python/conda/conda.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -77,7 +76,7 @@ func (c *Conda) Version() string {
func (c *Conda) Install(version string) error {
c.Log.BeginStep("Supplying conda")
var installer string
if installerDir, err := ioutil.TempDir("", "miniconda"); err != nil {
if installerDir, err := os.MkdirTemp("", "miniconda"); err != nil {
return err
} else {
installer = filepath.Join(installerDir, "miniconda.sh")
Expand All @@ -92,7 +91,7 @@ func (c *Conda) Install(version string) error {
}

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

Expand Down Expand Up @@ -151,7 +150,7 @@ func (c *Conda) Warning() error {
} else if !exists {
return nil
}
if contents, err := ioutil.ReadFile(filepath.Join(c.Stager.BuildDir(), "environment.yml")); err != nil {
if contents, err := os.ReadFile(filepath.Join(c.Stager.BuildDir(), "environment.yml")); err != nil {
return err
} else {
if bytes.Contains(contents, []byte("python=")) {
Expand Down
19 changes: 9 additions & 10 deletions src/python/conda/conda_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@ package conda_test

import (
"bytes"
io "io"
"io/ioutil"
"io"
"os"
"path/filepath"

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

"github.com/cloudfoundry/libbuildpack"
"github.com/cloudfoundry/libbuildpack/ansicleaner"
gomock "github.com/golang/mock/gomock"
"github.com/golang/mock/gomock"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
Expand All @@ -36,11 +35,11 @@ var _ = Describe("Conda", func() {
)

BeforeEach(func() {
buildDir, err = ioutil.TempDir("", "python-buildpack.build.")
buildDir, err = os.MkdirTemp("", "python-buildpack.build.")
Expect(err).To(BeNil())
cacheDir, err = ioutil.TempDir("", "python-buildpack.cache.")
cacheDir, err = os.MkdirTemp("", "python-buildpack.cache.")
Expect(err).To(BeNil())
depsDir, err = ioutil.TempDir("", "python-buildpack.deps.")
depsDir, err = os.MkdirTemp("", "python-buildpack.deps.")
Expect(err).To(BeNil())
depsIdx = "13"
depDir = filepath.Join(depsDir, depsIdx)
Expand Down Expand Up @@ -70,7 +69,7 @@ var _ = Describe("Conda", func() {
Describe("Version", func() {
Context("runtime.txt specifies python 3", func() {
BeforeEach(func() {
Expect(ioutil.WriteFile(filepath.Join(buildDir, "runtime.txt"), []byte("python-3.2.3"), 0644)).To(Succeed())
Expect(os.WriteFile(filepath.Join(buildDir, "runtime.txt"), []byte("python-3.2.3"), 0644)).To(Succeed())
})

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

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

It("make downloaded file executable", func() {
mockInstaller.EXPECT().InstallOnlyVersion("Miniconda7", gomock.Any()).Do(func(_, path string) {
Expect(ioutil.WriteFile(path, []byte{}, 0644)).To(Succeed())
Expect(os.WriteFile(path, []byte{}, 0644)).To(Succeed())
})
mockCommand.EXPECT().Execute("/", gomock.Any(), gomock.Any(), gomock.Any(), "-b", "-p", filepath.Join(depDir, "conda")).Do(func(_ string, _, _ io.Writer, path string, _ ...string) {
fi, err := os.Lstat(path)
Expand All @@ -111,7 +110,7 @@ var _ = Describe("Conda", func() {
It("deletes installer", func() {
var installerPath string
mockInstaller.EXPECT().InstallOnlyVersion("Miniconda7", gomock.Any()).Do(func(_, path string) {
Expect(ioutil.WriteFile(path, []byte{}, 0644)).To(Succeed())
Expect(os.WriteFile(path, []byte{}, 0644)).To(Succeed())
installerPath = path
})
mockCommand.EXPECT().Execute("/", gomock.Any(), gomock.Any(), gomock.Any(), "-b", "-p", filepath.Join(depDir, "conda")).Do(func(_ string, _, _ io.Writer, path string, _ ...string) {
Expand Down
3 changes: 1 addition & 2 deletions src/python/finalize/cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"io"
"io/ioutil"
"os"
"time"

Expand All @@ -15,7 +14,7 @@ import (
)

func main() {
logfile, err := ioutil.TempFile("", "cloudfoundry.python-buildpack.finalize")
logfile, err := os.CreateTemp("", "cloudfoundry.python-buildpack.finalize")
defer logfile.Close()
if err != nil {
logger := libbuildpack.NewLogger(os.Stdout)
Expand Down
13 changes: 6 additions & 7 deletions src/python/finalize/finalize.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"regexp"
Expand Down Expand Up @@ -72,24 +71,24 @@ func Run(f *Finalizer) error {

func (f *Finalizer) HandleCollectstatic() error {
if len(os.Getenv("DISABLE_COLLECTSTATIC")) > 0 {
f.Log.Debug("DISABLE_COLLECTSTATIC > 0, skipping collectstatic")
f.Log.Debug("DISABLE_COLLECTSTATIC > 0, skipping collectstatic")
return nil
}

exists, err := f.Requirements.FindAnyPackage(f.Stager.BuildDir(), "django", "Django")
if err != nil {
f.Log.Debug("Error during FindAnyPackage, skipping collectstatic")
f.Log.Debug("Error during FindAnyPackage, skipping collectstatic")
return err
}

if !exists {
f.Log.Debug("Django not in requirements, skipping collectstatic")
f.Log.Debug("Django not in requirements, skipping collectstatic")
return nil
}

managePyPath, err := f.ManagePyFinder.FindManagePy(f.Stager.BuildDir())
if err != nil {
f.Log.Debug("Error finding manage.py, skipping collectstatic")
f.Log.Debug("Error finding manage.py, skipping collectstatic")
return err
}

Expand Down Expand Up @@ -135,14 +134,14 @@ func (f *Finalizer) ReplaceDepsDirWithLiteral() error {
for _, dir := range dirs {
if err := filepath.Walk(dir, func(path string, _ os.FileInfo, _ error) error {
if strings.HasSuffix(path, ".pth") {
fileContents, err := ioutil.ReadFile(path)
fileContents, err := os.ReadFile(path)
if err != nil {
return err
}

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

if err := ioutil.WriteFile(path, fileContents, 0644); err != nil {
if err := os.WriteFile(path, fileContents, 0644); err != nil {
return err
}
}
Expand Down
15 changes: 7 additions & 8 deletions src/python/finalize/finalize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package finalize_test
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"os/exec"
"path"
Expand Down Expand Up @@ -37,10 +36,10 @@ var _ = Describe("Finalize", func() {
)

BeforeEach(func() {
buildDir, err = ioutil.TempDir("", "python-buildpack.build.")
buildDir, err = os.MkdirTemp("", "python-buildpack.build.")
Expect(err).To(BeNil())

depsDir, err = ioutil.TempDir("", "python-buildpack.deps.")
depsDir, err = os.MkdirTemp("", "python-buildpack.deps.")
Expect(err).To(BeNil())

depsIdx = "9"
Expand Down Expand Up @@ -135,15 +134,15 @@ var _ = Describe("Finalize", func() {
var file string
runSubjectAndReadContents := func() string {
Expect(finalizer.ReplaceDepsDirWithLiteral()).To(Succeed())
contents, err := ioutil.ReadFile(file)
contents, err := os.ReadFile(file)
Expect(err).ToNot(HaveOccurred())
return string(contents)
}
Context("file at site-packages root", func() {
BeforeEach(func() {
file = filepath.Join(depsDir, depsIdx, "python", "lib", "python2.7", "site-packages", "easy-install.pth")
Expect(os.MkdirAll(path.Dir(file), 0755)).To(Succeed())
Expect(ioutil.WriteFile(file, []byte("./pip-9.0.1-py2.7.egg\n"+depsDir+"/9/src/regcore\n"), 0644)).To(Succeed())
Expect(os.WriteFile(file, []byte("./pip-9.0.1-py2.7.egg\n"+depsDir+"/9/src/regcore\n"), 0644)).To(Succeed())
})
It("Converts DepsDir value to '$DEPS_DIR' string", func() {
Expect(runSubjectAndReadContents()).To(Equal("./pip-9.0.1-py2.7.egg\nDOLLAR_DEPS_DIR/9/src/regcore\n"))
Expand All @@ -153,7 +152,7 @@ var _ = Describe("Finalize", func() {
BeforeEach(func() {
file = filepath.Join(depsDir, depsIdx, "python", "lib", "python3.2", "site-packages", "something", "extra", "fred.pth")
Expect(os.MkdirAll(path.Dir(file), 0755)).To(Succeed())
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())
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())
})
It("Converts DepsDir value to '$DEPS_DIR' string", func() {
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"))
Expand All @@ -167,7 +166,7 @@ var _ = Describe("Finalize", func() {
BeforeEach(func() {
file = filepath.Join(depsDir, depsIdx, "python", "lib", "python2.7", "site-packages", "easy-install.pth")
Expect(os.MkdirAll(path.Dir(file), 0755)).To(Succeed())
Expect(ioutil.WriteFile(file, []byte("./pip-9.0.1-py2.7.egg\nDOLLAR_DEPS_DIR/9/src/regcore\n"), 0644)).To(Succeed())
Expect(os.WriteFile(file, []byte("./pip-9.0.1-py2.7.egg\nDOLLAR_DEPS_DIR/9/src/regcore\n"), 0644)).To(Succeed())
})
It("At runtime, converts the contents to the runtime depsDir", func() {
Expect(finalizer.ReplaceLiteralWithDepsDirAtRuntime()).To(Succeed())
Expand All @@ -176,7 +175,7 @@ var _ = Describe("Finalize", func() {
cmd.Env = append(os.Environ(), "DEPS_DIR="+depsDir)
Expect(cmd.Run()).To(Succeed())

contents, err := ioutil.ReadFile(file)
contents, err := os.ReadFile(file)
Expect(err).ToNot(HaveOccurred())
Expect(string(contents)).To(Equal("./pip-9.0.1-py2.7.egg\n" + depsDir + "/9/src/regcore\n"))
})
Expand Down
12 changes: 6 additions & 6 deletions src/python/hooks/appdynamics.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"sort"
"strings"

"github.com/cloudfoundry/libbuildpack"
"regexp"

"github.com/cloudfoundry/libbuildpack"
)

type Command interface {
Expand Down Expand Up @@ -73,7 +73,7 @@ func (h AppdynamicsHook) GenerateStartUpCommand(startCommand string) (string, er
}

func (h AppdynamicsHook) RewriteProcFile(procFilePath string) error {
startCommand, err := ioutil.ReadFile(procFilePath)
startCommand, err := os.ReadFile(procFilePath)
if err != nil {
return fmt.Errorf("Error reading file %s: %v", procFilePath, err)
}
Expand All @@ -82,7 +82,7 @@ func (h AppdynamicsHook) RewriteProcFile(procFilePath string) error {
return err
}

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

return nil
Expand All @@ -128,7 +128,7 @@ func (h AppdynamicsHook) RewriteProcFileWithAppdynamics(stager *libbuildpack.Sta
if err := h.RewriteProcFile(file); err != nil {
return err
}
fileContents, _ := ioutil.ReadFile(file)
fileContents, _ := os.ReadFile(file)
h.Log.Info(string(fileContents))
} else {
h.Log.Info("Cannot find Procfile, skipping this step!")
Expand Down
Loading

0 comments on commit def5564

Please sign in to comment.