Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

Commit 53405ea

Browse files
committed
api, common, db4s, webui: Replace deprecated ioutil functions
1 parent a2414f2 commit 53405ea

File tree

8 files changed

+12
-16
lines changed

8 files changed

+12
-16
lines changed

api/main.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"errors"
88
"fmt"
99
"html/template"
10-
"io/ioutil"
1110
"log"
1211
"net/http"
1312
"os"
@@ -85,7 +84,7 @@ func main() {
8584

8685
// Load our self signed CA chain
8786
ourCAPool = x509.NewCertPool()
88-
certFile, err := ioutil.ReadFile(com.Conf.DB4S.CAChain)
87+
certFile, err := os.ReadFile(com.Conf.DB4S.CAChain)
8988
if err != nil {
9089
fmt.Printf("Error opening Certificate Authority chain file: %v\n", err)
9190
return

common/cert.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import (
88
"crypto/x509/pkix"
99
"encoding/pem"
1010
"fmt"
11-
"io/ioutil"
1211
"log"
1312
"math/big"
13+
"os"
1414
"time"
1515
)
1616

@@ -43,7 +43,7 @@ func GenerateClientCert(userName string) (_ []byte, err error) {
4343
}
4444

4545
// Load the certificate used for signing (the intermediate certificate)
46-
certFile, err := ioutil.ReadFile(Conf.Sign.IntermediateCert)
46+
certFile, err := os.ReadFile(Conf.Sign.IntermediateCert)
4747
if err != nil {
4848
log.Printf("%s: Error opening intermediate certificate file: %v\n", pageName, err)
4949
return
@@ -60,7 +60,7 @@ func GenerateClientCert(userName string) (_ []byte, err error) {
6060
}
6161

6262
// Load the private key for the intermediate certificate
63-
intKeyFile, err := ioutil.ReadFile(Conf.Sign.IntermediateKey)
63+
intKeyFile, err := os.ReadFile(Conf.Sign.IntermediateKey)
6464
if err != nil {
6565
log.Printf("%s: Error opening intermediate certificate key: %v\n", pageName, err)
6666
return

common/licences.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package common
22

33
import (
4-
"io/ioutil"
54
"log"
5+
"os"
66
"path/filepath"
77
)
88

@@ -73,7 +73,7 @@ func AddDefaultLicences() (err error) {
7373
txt := []byte{}
7474
if l.Path != "" {
7575
// Read the file contents
76-
txt, err = ioutil.ReadFile(filepath.Join(Conf.Licence.LicenceDir, l.Path))
76+
txt, err = os.ReadFile(filepath.Join(Conf.Licence.LicenceDir, l.Path))
7777
if err != nil {
7878
return err
7979
}

common/merge.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package common
33
import (
44
"fmt"
55
"io"
6-
"io/ioutil"
76
"os"
87
"strings"
98
"time"
@@ -184,7 +183,7 @@ func performMerge(destOwner, destFolder, destName, destBranch, destCommitID, src
184183
}
185184

186185
// Create a temporary file for the new database
187-
tmpFile, err := ioutil.TempFile(Conf.DiskCache.Directory, "dbhub-merge-*.db")
186+
tmpFile, err := os.CreateTemp(Conf.DiskCache.Directory, "dbhub-merge-*.db")
188187
if err != nil {
189188
return
190189
}

common/responses.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func UploadResponse(w http.ResponseWriter, r *http.Request, loggedInUser, target
111111
}
112112
if err != nil {
113113
if err.Error() == "http: no such file" {
114-
// Check for a 'file1' FormFile too, as the some clients can't use 'file' (without a number) due to a design bug
114+
// Check for a 'file1' FormFile too, as some clients can't use 'file' (without a number) due to a design bug
115115
tempFile, handler, err = r.FormFile("file1")
116116
if err != nil {
117117
log.Printf("Uploading file failed: %v\n", err)

common/util.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"errors"
88
"fmt"
99
"io"
10-
"io/ioutil"
1110
"log"
1211
"math/rand"
1312
"net/http"
@@ -45,7 +44,7 @@ func AddDatabase(loggedInUser, dbOwner, dbFolder, dbName string, createBranch bo
4544
}
4645

4746
// Create a temporary file to store the database in
48-
tempDB, err := ioutil.TempFile(Conf.DiskCache.Directory, "dbhub-upload-")
47+
tempDB, err := os.CreateTemp(Conf.DiskCache.Directory, "dbhub-upload-")
4948
if err != nil {
5049
log.Printf("Error creating temporary file. User: '%s', Database: '%s%s%s', Error: %v\n", loggedInUser,
5150
SanitiseLogString(dbOwner), SanitiseLogString(dbFolder), SanitiseLogString(dbName), err)

db4s/main.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"encoding/json"
1010
"fmt"
1111
"io"
12-
"io/ioutil"
1312
"log"
1413
"net/http"
1514
"net/url"
@@ -76,7 +75,7 @@ func main() {
7675

7776
// Load our self signed CA chain
7877
ourCAPool = x509.NewCertPool()
79-
certFile, err := ioutil.ReadFile(com.Conf.DB4S.CAChain)
78+
certFile, err := os.ReadFile(com.Conf.DB4S.CAChain)
8079
if err != nil {
8180
fmt.Printf("Error opening Certificate Authority chain file: %v\n", err)
8281
return

webui/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"encoding/json"
77
"fmt"
88
"html/template"
9-
"io/ioutil"
9+
"io"
1010
"log"
1111
"net/http"
1212
"net/url"
@@ -121,7 +121,7 @@ func auth0CallbackHandler(w http.ResponseWriter, r *http.Request) {
121121
errorPage(w, r, http.StatusInternalServerError, err.Error())
122122
return
123123
}
124-
raw, err := ioutil.ReadAll(userInfo.Body)
124+
raw, err := io.ReadAll(userInfo.Body)
125125
defer userInfo.Body.Close()
126126
if err != nil {
127127
errorPage(w, r, http.StatusInternalServerError, err.Error())

0 commit comments

Comments
 (0)