mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-29 13:05:46 +00:00
refactor: move from io/ioutil to io and os packages
The io/ioutil package has been deprecated as of Go 1.16 [1]. This commit replaces the existing io/ioutil functions with their new definitions in io and os packages. Reference: https://golang.org/doc/go1.16#ioutil Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
This commit is contained in:
parent
027111fb5a
commit
f0347e841f
@ -9,7 +9,6 @@
|
|||||||
package atomicfile // import "tailscale.com/atomicfile"
|
package atomicfile // import "tailscale.com/atomicfile"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
@ -18,7 +17,7 @@
|
|||||||
// WriteFile writes data to filename+some suffix, then renames it
|
// WriteFile writes data to filename+some suffix, then renames it
|
||||||
// into filename. The perm argument is ignored on Windows.
|
// into filename. The perm argument is ignored on Windows.
|
||||||
func WriteFile(filename string, data []byte, perm os.FileMode) (err error) {
|
func WriteFile(filename string, data []byte, perm os.FileMode) (err error) {
|
||||||
f, err := ioutil.TempFile(filepath.Dir(filename), filepath.Base(filename)+".tmp")
|
f, err := os.CreateTemp(filepath.Dir(filename), filepath.Base(filename)+".tmp")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptrace"
|
"net/http/httptrace"
|
||||||
@ -137,7 +136,7 @@ func (lc *LocalClient) doLocalRequestNiceError(req *http.Request) (*http.Respons
|
|||||||
onVersionMismatch(ipn.IPCVersion(), server)
|
onVersionMismatch(ipn.IPCVersion(), server)
|
||||||
}
|
}
|
||||||
if res.StatusCode == 403 {
|
if res.StatusCode == 403 {
|
||||||
all, _ := ioutil.ReadAll(res.Body)
|
all, _ := io.ReadAll(res.Body)
|
||||||
return nil, &AccessDeniedError{errors.New(errorMessageFromBody(all))}
|
return nil, &AccessDeniedError{errors.New(errorMessageFromBody(all))}
|
||||||
}
|
}
|
||||||
return res, nil
|
return res, nil
|
||||||
@ -207,7 +206,7 @@ func (lc *LocalClient) send(ctx context.Context, method, path string, wantStatus
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer res.Body.Close()
|
defer res.Body.Close()
|
||||||
slurp, err := ioutil.ReadAll(res.Body)
|
slurp, err := io.ReadAll(res.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -365,7 +364,7 @@ func (lc *LocalClient) GetWaitingFile(ctx context.Context, baseName string) (rc
|
|||||||
return nil, 0, fmt.Errorf("unexpected chunking")
|
return nil, 0, fmt.Errorf("unexpected chunking")
|
||||||
}
|
}
|
||||||
if res.StatusCode != 200 {
|
if res.StatusCode != 200 {
|
||||||
body, _ := ioutil.ReadAll(res.Body)
|
body, _ := io.ReadAll(res.Body)
|
||||||
res.Body.Close()
|
res.Body.Close()
|
||||||
return nil, 0, fmt.Errorf("HTTP %s: %s", res.Status, body)
|
return nil, 0, fmt.Errorf("HTTP %s: %s", res.Status, body)
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -131,7 +130,7 @@ func (c *Client) sendRequest(req *http.Request) ([]byte, *http.Response, error)
|
|||||||
|
|
||||||
// Read response. Limit the response to 10MB.
|
// Read response. Limit the response to 10MB.
|
||||||
body := io.LimitReader(resp.Body, maxReadSize+1)
|
body := io.LimitReader(resp.Body, maxReadSize+1)
|
||||||
b, err := ioutil.ReadAll(body)
|
b, err := io.ReadAll(body)
|
||||||
if len(b) > maxReadSize {
|
if len(b) > maxReadSize {
|
||||||
err = errors.New("API response too large")
|
err = errors.New("API response too large")
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,6 @@
|
|||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
"math"
|
"math"
|
||||||
"net"
|
"net"
|
||||||
@ -99,7 +98,7 @@ func loadConfig() config {
|
|||||||
}
|
}
|
||||||
log.Printf("no config path specified; using %s", *configPath)
|
log.Printf("no config path specified; using %s", *configPath)
|
||||||
}
|
}
|
||||||
b, err := ioutil.ReadFile(*configPath)
|
b, err := os.ReadFile(*configPath)
|
||||||
switch {
|
switch {
|
||||||
case errors.Is(err, os.ErrNotExist):
|
case errors.Is(err, os.ErrNotExist):
|
||||||
return writeNewConfig()
|
return writeNewConfig()
|
||||||
@ -155,7 +154,7 @@ func main() {
|
|||||||
s.SetVerifyClient(*verifyClients)
|
s.SetVerifyClient(*verifyClients)
|
||||||
|
|
||||||
if *meshPSKFile != "" {
|
if *meshPSKFile != "" {
|
||||||
b, err := ioutil.ReadFile(*meshPSKFile)
|
b, err := os.ReadFile(*meshPSKFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,6 @@
|
|||||||
"errors"
|
"errors"
|
||||||
"flag"
|
"flag"
|
||||||
"html/template"
|
"html/template"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
@ -106,7 +105,7 @@ func devMode() bool { return *httpsAddr == "" && *httpAddr != "" }
|
|||||||
|
|
||||||
func getTmpl() (*template.Template, error) {
|
func getTmpl() (*template.Template, error) {
|
||||||
if devMode() {
|
if devMode() {
|
||||||
tmplData, err := ioutil.ReadFile("hello.tmpl.html")
|
tmplData, err := os.ReadFile("hello.tmpl.html")
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
log.Printf("using baked-in template in dev mode; can't find hello.tmpl.html in current directory")
|
log.Printf("using baked-in template in dev mode; can't find hello.tmpl.html in current directory")
|
||||||
return tmpl, nil
|
return tmpl, nil
|
||||||
|
@ -10,7 +10,6 @@
|
|||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"sort"
|
"sort"
|
||||||
@ -202,7 +201,7 @@ func prodDERPMap(ctx context.Context, httpc *http.Client) (*tailcfg.DERPMap, err
|
|||||||
return nil, fmt.Errorf("fetch prodDERPMap failed: %w", err)
|
return nil, fmt.Errorf("fetch prodDERPMap failed: %w", err)
|
||||||
}
|
}
|
||||||
defer res.Body.Close()
|
defer res.Body.Close()
|
||||||
b, err := ioutil.ReadAll(io.LimitReader(res.Body, 1<<20))
|
b, err := io.ReadAll(io.LimitReader(res.Body, 1<<20))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("fetch prodDERPMap failed: %w", err)
|
return nil, fmt.Errorf("fetch prodDERPMap failed: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -254,7 +253,7 @@ func qnapAuthnFinish(user, url string) (string, *qnapAuthResponse, error) {
|
|||||||
return "", nil, err
|
return "", nil, err
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
out, err := ioutil.ReadAll(resp.Body)
|
out, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", nil, err
|
return "", nil, err
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -173,7 +172,7 @@ func checkDerp(ctx context.Context, derpRegion string) error {
|
|||||||
return fmt.Errorf("fetch derp map failed: %w", err)
|
return fmt.Errorf("fetch derp map failed: %w", err)
|
||||||
}
|
}
|
||||||
defer res.Body.Close()
|
defer res.Body.Close()
|
||||||
b, err := ioutil.ReadAll(io.LimitReader(res.Body, 1<<20))
|
b, err := io.ReadAll(io.LimitReader(res.Body, 1<<20))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("fetch derp map failed: %w", err)
|
return fmt.Errorf("fetch derp map failed: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,6 @@
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -142,7 +141,7 @@ func installSystemDaemonDarwin(args []string) (err error) {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := ioutil.WriteFile(sysPlist, []byte(darwinLaunchdPlist), 0700); err != nil {
|
if err := os.WriteFile(sysPlist, []byte(darwinLaunchdPlist), 0700); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,7 +7,6 @@
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
@ -47,7 +46,7 @@ func runBuild() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Cannot fix esbuild metadata paths: %v", err)
|
log.Fatalf("Cannot fix esbuild metadata paths: %v", err)
|
||||||
}
|
}
|
||||||
if err := ioutil.WriteFile(path.Join(*distDir, "/esbuild-metadata.json"), metadataBytes, 0666); err != nil {
|
if err := os.WriteFile(path.Join(*distDir, "/esbuild-metadata.json"), metadataBytes, 0666); err != nil {
|
||||||
log.Fatalf("Cannot write metadata: %v", err)
|
log.Fatalf("Cannot write metadata: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
@ -183,7 +182,7 @@ func setupEsbuildWasm(build esbuild.PluginBuild, dev bool) {
|
|||||||
|
|
||||||
func buildWasm(dev bool) ([]byte, error) {
|
func buildWasm(dev bool) ([]byte, error) {
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
outputFile, err := ioutil.TempFile("", "main.*.wasm")
|
outputFile, err := os.CreateTemp("", "main.*.wasm")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Cannot create main.wasm output file: %w", err)
|
return nil, fmt.Errorf("Cannot create main.wasm output file: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,6 @@
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
@ -75,7 +74,7 @@ func generateServeIndex(distFS fs.FS) ([]byte, error) {
|
|||||||
return nil, fmt.Errorf("Could not open esbuild-metadata.json: %w", err)
|
return nil, fmt.Errorf("Could not open esbuild-metadata.json: %w", err)
|
||||||
}
|
}
|
||||||
defer esbuildMetadataFile.Close()
|
defer esbuildMetadataFile.Close()
|
||||||
esbuildMetadataBytes, err := ioutil.ReadAll(esbuildMetadataFile)
|
esbuildMetadataBytes, err := io.ReadAll(esbuildMetadataFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Could not read esbuild-metadata.json: %w", err)
|
return nil, fmt.Errorf("Could not read esbuild-metadata.json: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,6 @@
|
|||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
@ -523,7 +522,7 @@ func (c *Direct) doLogin(ctx context.Context, opt loginOpt) (mustRegen bool, new
|
|||||||
return regen, opt.URL, fmt.Errorf("register request: %w", err)
|
return regen, opt.URL, fmt.Errorf("register request: %w", err)
|
||||||
}
|
}
|
||||||
if res.StatusCode != 200 {
|
if res.StatusCode != 200 {
|
||||||
msg, _ := ioutil.ReadAll(res.Body)
|
msg, _ := io.ReadAll(res.Body)
|
||||||
res.Body.Close()
|
res.Body.Close()
|
||||||
return regen, opt.URL, fmt.Errorf("register request: http %d: %.200s",
|
return regen, opt.URL, fmt.Errorf("register request: http %d: %.200s",
|
||||||
res.StatusCode, strings.TrimSpace(string(msg)))
|
res.StatusCode, strings.TrimSpace(string(msg)))
|
||||||
@ -804,7 +803,7 @@ func (c *Direct) sendMapRequest(ctx context.Context, maxPolls int, readOnly bool
|
|||||||
}
|
}
|
||||||
vlogf("netmap: Do = %v after %v", res.StatusCode, time.Since(t0).Round(time.Millisecond))
|
vlogf("netmap: Do = %v after %v", res.StatusCode, time.Since(t0).Round(time.Millisecond))
|
||||||
if res.StatusCode != 200 {
|
if res.StatusCode != 200 {
|
||||||
msg, _ := ioutil.ReadAll(res.Body)
|
msg, _ := io.ReadAll(res.Body)
|
||||||
res.Body.Close()
|
res.Body.Close()
|
||||||
return fmt.Errorf("initial fetch failed %d: %.200s",
|
return fmt.Errorf("initial fetch failed %d: %.200s",
|
||||||
res.StatusCode, strings.TrimSpace(string(msg)))
|
res.StatusCode, strings.TrimSpace(string(msg)))
|
||||||
@ -814,7 +813,7 @@ func (c *Direct) sendMapRequest(ctx context.Context, maxPolls int, readOnly bool
|
|||||||
health.NoteMapRequestHeard(request)
|
health.NoteMapRequestHeard(request)
|
||||||
|
|
||||||
if cb == nil {
|
if cb == nil {
|
||||||
io.Copy(ioutil.Discard, res.Body)
|
io.Copy(io.Discard, res.Body)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -998,7 +997,7 @@ func (c *Direct) sendMapRequest(ctx context.Context, maxPolls int, readOnly bool
|
|||||||
// it uses the serverKey and mkey to decode the message from the NaCl-crypto-box.
|
// it uses the serverKey and mkey to decode the message from the NaCl-crypto-box.
|
||||||
func decode(res *http.Response, v any, serverKey, serverNoiseKey key.MachinePublic, mkey key.MachinePrivate) error {
|
func decode(res *http.Response, v any, serverKey, serverNoiseKey key.MachinePublic, mkey key.MachinePrivate) error {
|
||||||
defer res.Body.Close()
|
defer res.Body.Close()
|
||||||
msg, err := ioutil.ReadAll(io.LimitReader(res.Body, 1<<20))
|
msg, err := io.ReadAll(io.LimitReader(res.Body, 1<<20))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -1110,7 +1109,7 @@ func loadServerPubKeys(ctx context.Context, httpc *http.Client, serverURL string
|
|||||||
return nil, fmt.Errorf("fetch control key: %v", err)
|
return nil, fmt.Errorf("fetch control key: %v", err)
|
||||||
}
|
}
|
||||||
defer res.Body.Close()
|
defer res.Body.Close()
|
||||||
b, err := ioutil.ReadAll(io.LimitReader(res.Body, 64<<10))
|
b, err := io.ReadAll(io.LimitReader(res.Body, 64<<10))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("fetch control key response: %v", err)
|
return nil, fmt.Errorf("fetch control key response: %v", err)
|
||||||
}
|
}
|
||||||
@ -1398,7 +1397,7 @@ func (c *Direct) setDNSNoise(ctx context.Context, req *tailcfg.SetDNSRequest) er
|
|||||||
}
|
}
|
||||||
defer res.Body.Close()
|
defer res.Body.Close()
|
||||||
if res.StatusCode != 200 {
|
if res.StatusCode != 200 {
|
||||||
msg, _ := ioutil.ReadAll(res.Body)
|
msg, _ := io.ReadAll(res.Body)
|
||||||
return fmt.Errorf("set-dns response: %v, %.200s", res.Status, strings.TrimSpace(string(msg)))
|
return fmt.Errorf("set-dns response: %v, %.200s", res.Status, strings.TrimSpace(string(msg)))
|
||||||
}
|
}
|
||||||
var setDNSRes tailcfg.SetDNSResponse
|
var setDNSRes tailcfg.SetDNSResponse
|
||||||
@ -1464,7 +1463,7 @@ func (c *Direct) SetDNS(ctx context.Context, req *tailcfg.SetDNSRequest) (err er
|
|||||||
}
|
}
|
||||||
defer res.Body.Close()
|
defer res.Body.Close()
|
||||||
if res.StatusCode != 200 {
|
if res.StatusCode != 200 {
|
||||||
msg, _ := ioutil.ReadAll(res.Body)
|
msg, _ := io.ReadAll(res.Body)
|
||||||
return fmt.Errorf("set-dns response: %v, %.200s", res.Status, strings.TrimSpace(string(msg)))
|
return fmt.Errorf("set-dns response: %v, %.200s", res.Status, strings.TrimSpace(string(msg)))
|
||||||
}
|
}
|
||||||
var setDNSRes tailcfg.SetDNSResponse
|
var setDNSRes tailcfg.SetDNSResponse
|
||||||
|
@ -19,7 +19,6 @@
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -195,7 +194,7 @@ func readFrame(br *bufio.Reader, maxSize uint32, b []byte) (t frameType, frameLe
|
|||||||
}
|
}
|
||||||
remain := frameLen - uint32(n)
|
remain := frameLen - uint32(n)
|
||||||
if remain > 0 {
|
if remain > 0 {
|
||||||
if _, err := io.CopyN(ioutil.Discard, br, int64(remain)); err != nil {
|
if _, err := io.CopyN(io.Discard, br, int64(remain)); err != nil {
|
||||||
return 0, 0, err
|
return 0, 0, err
|
||||||
}
|
}
|
||||||
err = io.ErrShortBuffer
|
err = io.ErrShortBuffer
|
||||||
|
@ -18,7 +18,6 @@
|
|||||||
"expvar"
|
"expvar"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
"math"
|
"math"
|
||||||
"math/big"
|
"math/big"
|
||||||
@ -758,7 +757,7 @@ func (c *sclient) run(ctx context.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *sclient) handleUnknownFrame(ft frameType, fl uint32) error {
|
func (c *sclient) handleUnknownFrame(ft frameType, fl uint32) error {
|
||||||
_, err := io.CopyN(ioutil.Discard, c.br, int64(fl))
|
_, err := io.CopyN(io.Discard, c.br, int64(fl))
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -801,7 +800,7 @@ func (c *sclient) handleFramePing(ft frameType, fl uint32) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if extra := int64(fl) - int64(len(m)); extra > 0 {
|
if extra := int64(fl) - int64(len(m)); extra > 0 {
|
||||||
_, err = io.CopyN(ioutil.Discard, c.br, extra)
|
_, err = io.CopyN(io.Discard, c.br, extra)
|
||||||
}
|
}
|
||||||
select {
|
select {
|
||||||
case c.sendPongCh <- [8]byte(m):
|
case c.sendPongCh <- [8]byte(m):
|
||||||
@ -1828,7 +1827,7 @@ func (s *Server) ServeDebugTraffic(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
var bufioWriterPool = &sync.Pool{
|
var bufioWriterPool = &sync.Pool{
|
||||||
New: func() any {
|
New: func() any {
|
||||||
return bufio.NewWriterSize(ioutil.Discard, 2<<10)
|
return bufio.NewWriterSize(io.Discard, 2<<10)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1861,7 +1860,7 @@ func (w *lazyBufioWriter) Flush() error {
|
|||||||
}
|
}
|
||||||
err := w.lbw.Flush()
|
err := w.lbw.Flush()
|
||||||
|
|
||||||
w.lbw.Reset(ioutil.Discard)
|
w.lbw.Reset(io.Discard)
|
||||||
bufioWriterPool.Put(w.lbw)
|
bufioWriterPool.Put(w.lbw)
|
||||||
w.lbw = nil
|
w.lbw = nil
|
||||||
|
|
||||||
|
@ -15,9 +15,9 @@
|
|||||||
"expvar"
|
"expvar"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
@ -1240,7 +1240,7 @@ func benchmarkSendRecvSize(b *testing.B, packetSize int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkWriteUint32(b *testing.B) {
|
func BenchmarkWriteUint32(b *testing.B) {
|
||||||
w := bufio.NewWriter(ioutil.Discard)
|
w := bufio.NewWriter(io.Discard)
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
@ -1279,9 +1279,9 @@ func waitConnect(t testing.TB, c *Client) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestParseSSOutput(t *testing.T) {
|
func TestParseSSOutput(t *testing.T) {
|
||||||
contents, err := ioutil.ReadFile("testdata/example_ss.txt")
|
contents, err := os.ReadFile("testdata/example_ss.txt")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("ioutil.Readfile(example_ss.txt) failed: %v", err)
|
t.Errorf("os.ReadFile(example_ss.txt) failed: %v", err)
|
||||||
}
|
}
|
||||||
seen := parseSSOutput(string(contents))
|
seen := parseSSOutput(string(contents))
|
||||||
if len(seen) == 0 {
|
if len(seen) == 0 {
|
||||||
|
@ -19,7 +19,6 @@
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/netip"
|
"net/netip"
|
||||||
@ -432,7 +431,7 @@ func (c *Client) connect(ctx context.Context, caller string) (client *derp.Clien
|
|||||||
return nil, 0, err
|
return nil, 0, err
|
||||||
}
|
}
|
||||||
if resp.StatusCode != http.StatusSwitchingProtocols {
|
if resp.StatusCode != http.StatusSwitchingProtocols {
|
||||||
b, _ := ioutil.ReadAll(resp.Body)
|
b, _ := io.ReadAll(resp.Body)
|
||||||
resp.Body.Close()
|
resp.Body.Close()
|
||||||
return nil, 0, fmt.Errorf("GET failed: %v: %s", err, b)
|
return nil, 0, fmt.Errorf("GET failed: %v: %s", err, b)
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,6 @@
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -99,11 +98,11 @@ func linuxVersionMeta() (meta versionMeta) {
|
|||||||
case distro.OpenWrt:
|
case distro.OpenWrt:
|
||||||
propFile = "/etc/openwrt_release"
|
propFile = "/etc/openwrt_release"
|
||||||
case distro.WDMyCloud:
|
case distro.WDMyCloud:
|
||||||
slurp, _ := ioutil.ReadFile("/etc/version")
|
slurp, _ := os.ReadFile("/etc/version")
|
||||||
meta.DistroVersion = string(bytes.TrimSpace(slurp))
|
meta.DistroVersion = string(bytes.TrimSpace(slurp))
|
||||||
return
|
return
|
||||||
case distro.QNAP:
|
case distro.QNAP:
|
||||||
slurp, _ := ioutil.ReadFile("/etc/version_info")
|
slurp, _ := os.ReadFile("/etc/version_info")
|
||||||
meta.DistroVersion = getQnapQtsVersion(string(slurp))
|
meta.DistroVersion = getQnapQtsVersion(string(slurp))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -133,7 +132,7 @@ func linuxVersionMeta() (meta versionMeta) {
|
|||||||
case "debian":
|
case "debian":
|
||||||
// Debian's VERSION_ID is just like "11". But /etc/debian_version has "11.5" normally.
|
// Debian's VERSION_ID is just like "11". But /etc/debian_version has "11.5" normally.
|
||||||
// Or "bookworm/sid" on sid/testing.
|
// Or "bookworm/sid" on sid/testing.
|
||||||
slurp, _ := ioutil.ReadFile("/etc/debian_version")
|
slurp, _ := os.ReadFile("/etc/debian_version")
|
||||||
if v := string(bytes.TrimSpace(slurp)); v != "" {
|
if v := string(bytes.TrimSpace(slurp)); v != "" {
|
||||||
if '0' <= v[0] && v[0] <= '9' {
|
if '0' <= v[0] && v[0] <= '9' {
|
||||||
meta.DistroVersion = v
|
meta.DistroVersion = v
|
||||||
@ -143,7 +142,7 @@ func linuxVersionMeta() (meta versionMeta) {
|
|||||||
}
|
}
|
||||||
case "", "centos": // CentOS 6 has no /etc/os-release, so its id is ""
|
case "", "centos": // CentOS 6 has no /etc/os-release, so its id is ""
|
||||||
if meta.DistroVersion == "" {
|
if meta.DistroVersion == "" {
|
||||||
if cr, _ := ioutil.ReadFile("/etc/centos-release"); len(cr) > 0 { // "CentOS release 6.10 (Final)
|
if cr, _ := os.ReadFile("/etc/centos-release"); len(cr) > 0 { // "CentOS release 6.10 (Final)
|
||||||
meta.DistroVersion = string(bytes.TrimSpace(cr))
|
meta.DistroVersion = string(bytes.TrimSpace(cr))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,6 @@
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"io/ioutil"
|
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
@ -87,7 +86,7 @@ func fileHasContents(name string, want string) check {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
path := filepath.Join(root, name)
|
path := filepath.Join(root, name)
|
||||||
got, err := ioutil.ReadFile(path)
|
got, err := os.ReadFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("fileHasContents: %v", err)
|
t.Errorf("fileHasContents: %v", err)
|
||||||
return
|
return
|
||||||
@ -517,7 +516,7 @@ func TestDeletedMarkers(t *testing.T) {
|
|||||||
}
|
}
|
||||||
wantEmptyTempDir := func() {
|
wantEmptyTempDir := func() {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
if fis, err := ioutil.ReadDir(dir); err != nil {
|
if fis, err := os.ReadDir(dir); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
} else if len(fis) > 0 && runtime.GOOS != "windows" {
|
} else if len(fis) > 0 && runtime.GOOS != "windows" {
|
||||||
for _, fi := range fis {
|
for _, fi := range fis {
|
||||||
|
@ -18,7 +18,6 @@
|
|||||||
"encoding/pem"
|
"encoding/pem"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
@ -80,7 +79,7 @@ func (b *LocalBackend) hostKeyFileOrCreate(keyDir, typ string) ([]byte, error) {
|
|||||||
defer keyGenMu.Unlock()
|
defer keyGenMu.Unlock()
|
||||||
|
|
||||||
path := filepath.Join(keyDir, "ssh_host_"+typ+"_key")
|
path := filepath.Join(keyDir, "ssh_host_"+typ+"_key")
|
||||||
v, err := ioutil.ReadFile(path)
|
v, err := os.ReadFile(path)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return v, nil
|
return v, nil
|
||||||
}
|
}
|
||||||
@ -121,7 +120,7 @@ func (b *LocalBackend) hostKeyFileOrCreate(keyDir, typ string) ([]byte, error) {
|
|||||||
func (b *LocalBackend) getSystemSSH_HostKeys() (ret map[string]ssh.Signer) {
|
func (b *LocalBackend) getSystemSSH_HostKeys() (ret map[string]ssh.Signer) {
|
||||||
for _, typ := range keyTypes {
|
for _, typ := range keyTypes {
|
||||||
filename := "/etc/ssh/ssh_host_" + typ + "_key"
|
filename := "/etc/ssh/ssh_host_" + typ + "_key"
|
||||||
hostKey, err := ioutil.ReadFile(filename)
|
hostKey, err := os.ReadFile(filename)
|
||||||
if err != nil || len(bytes.TrimSpace(hostKey)) == 0 {
|
if err != nil || len(bytes.TrimSpace(hostKey)) == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,6 @@
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -215,7 +214,7 @@ func (s *Server) blockWhileInUse(conn io.Reader, ci connIdentity) {
|
|||||||
s.logf("blocking client while server in use; connIdentity=%v", ci)
|
s.logf("blocking client while server in use; connIdentity=%v", ci)
|
||||||
connDone := make(chan struct{})
|
connDone := make(chan struct{})
|
||||||
go func() {
|
go func() {
|
||||||
io.Copy(ioutil.Discard, conn)
|
io.Copy(io.Discard, conn)
|
||||||
close(connDone)
|
close(connDone)
|
||||||
}()
|
}()
|
||||||
ch := make(chan struct{}, 1)
|
ch := make(chan struct{}, 1)
|
||||||
@ -1175,7 +1174,7 @@ func findTrueNASTaildropDir(name string) (dir string, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// but if running on the host, it may be something like /mnt/Primary/Taildrop
|
// but if running on the host, it may be something like /mnt/Primary/Taildrop
|
||||||
fis, err := ioutil.ReadDir("/mnt")
|
fis, err := os.ReadDir("/mnt")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("error reading /mnt: %w", err)
|
return "", fmt.Errorf("error reading /mnt: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,6 @@
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -293,7 +292,7 @@ func (h *Handler) getCertPEM(ctx context.Context, logf logger.Logf, traceACME fu
|
|||||||
if err := encodeECDSAKey(&privPEM, certPrivKey); err != nil {
|
if err := encodeECDSAKey(&privPEM, certPrivKey); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if err := ioutil.WriteFile(keyFile(dir, domain), privPEM.Bytes(), 0600); err != nil {
|
if err := os.WriteFile(keyFile(dir, domain), privPEM.Bytes(), 0600); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -316,7 +315,7 @@ func (h *Handler) getCertPEM(ctx context.Context, logf logger.Logf, traceACME fu
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err := ioutil.WriteFile(certFile(dir, domain), certPEM.Bytes(), 0644); err != nil {
|
if err := os.WriteFile(certFile(dir, domain), certPEM.Bytes(), 0644); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -372,7 +371,7 @@ func parsePrivateKey(der []byte) (crypto.Signer, error) {
|
|||||||
|
|
||||||
func acmeKey(dir string) (crypto.Signer, error) {
|
func acmeKey(dir string) (crypto.Signer, error) {
|
||||||
pemName := filepath.Join(dir, "acme-account.key.pem")
|
pemName := filepath.Join(dir, "acme-account.key.pem")
|
||||||
if v, err := ioutil.ReadFile(pemName); err == nil {
|
if v, err := os.ReadFile(pemName); err == nil {
|
||||||
priv, _ := pem.Decode(v)
|
priv, _ := pem.Decode(v)
|
||||||
if priv == nil || !strings.Contains(priv.Type, "PRIVATE") {
|
if priv == nil || !strings.Contains(priv.Type, "PRIVATE") {
|
||||||
return nil, errors.New("acme/autocert: invalid account key found in cache")
|
return nil, errors.New("acme/autocert: invalid account key found in cache")
|
||||||
@ -388,7 +387,7 @@ func acmeKey(dir string) (crypto.Signer, error) {
|
|||||||
if err := encodeECDSAKey(&pemBuf, privKey); err != nil {
|
if err := encodeECDSAKey(&pemBuf, privKey); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if err := ioutil.WriteFile(pemName, pemBuf.Bytes(), 0600); err != nil {
|
if err := os.WriteFile(pemName, pemBuf.Bytes(), 0600); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return privKey, nil
|
return privKey, nil
|
||||||
|
@ -9,7 +9,6 @@
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
"net/netip"
|
"net/netip"
|
||||||
"os"
|
"os"
|
||||||
@ -618,7 +617,7 @@ func PrefsFromBytes(b []byte) (*Prefs, error) {
|
|||||||
// LoadPrefs loads a legacy relaynode config file into Prefs
|
// LoadPrefs loads a legacy relaynode config file into Prefs
|
||||||
// with sensible migration defaults set.
|
// with sensible migration defaults set.
|
||||||
func LoadPrefs(filename string) (*Prefs, error) {
|
func LoadPrefs(filename string) (*Prefs, error) {
|
||||||
data, err := ioutil.ReadFile(filename)
|
data, err := os.ReadFile(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("LoadPrefs open: %w", err) // err includes path
|
return nil, fmt.Errorf("LoadPrefs open: %w", err) // err includes path
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,6 @@
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"net/netip"
|
"net/netip"
|
||||||
"os"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
@ -474,7 +473,7 @@ func TestLoadPrefsNotExist(t *testing.T) {
|
|||||||
// TestLoadPrefsFileWithZeroInIt verifies that LoadPrefs hanldes corrupted input files.
|
// TestLoadPrefsFileWithZeroInIt verifies that LoadPrefs hanldes corrupted input files.
|
||||||
// See issue #954 for details.
|
// See issue #954 for details.
|
||||||
func TestLoadPrefsFileWithZeroInIt(t *testing.T) {
|
func TestLoadPrefsFileWithZeroInIt(t *testing.T) {
|
||||||
f, err := ioutil.TempFile("", "TestLoadPrefsFileWithZeroInIt")
|
f, err := os.CreateTemp("", "TestLoadPrefsFileWithZeroInIt")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,6 @@
|
|||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
@ -128,7 +127,7 @@ func NewFileStore(logf logger.Logf, path string) (ipn.StateStore, error) {
|
|||||||
return nil, fmt.Errorf("creating state directory: %w", err)
|
return nil, fmt.Errorf("creating state directory: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
bs, err := ioutil.ReadFile(path)
|
bs, err := os.ReadFile(path)
|
||||||
|
|
||||||
// Treat an empty file as a missing file.
|
// Treat an empty file as a missing file.
|
||||||
// (https://github.com/tailscale/tailscale/issues/895#issuecomment-723255589)
|
// (https://github.com/tailscale/tailscale/issues/895#issuecomment-723255589)
|
||||||
|
@ -9,7 +9,6 @@
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -186,12 +185,18 @@ func (w *logFileWriter) startNewFileLocked() {
|
|||||||
//
|
//
|
||||||
// w.mu must be held.
|
// w.mu must be held.
|
||||||
func (w *logFileWriter) cleanLocked() {
|
func (w *logFileWriter) cleanLocked() {
|
||||||
fis, _ := ioutil.ReadDir(w.dir)
|
entries, _ := os.ReadDir(w.dir)
|
||||||
prefix := w.fileBasePrefix + "-"
|
prefix := w.fileBasePrefix + "-"
|
||||||
fileSize := map[string]int64{}
|
fileSize := map[string]int64{}
|
||||||
var files []string
|
var files []string
|
||||||
var sumSize int64
|
var sumSize int64
|
||||||
for _, fi := range fis {
|
for _, entry := range entries {
|
||||||
|
fi, err := entry.Info()
|
||||||
|
if err != nil {
|
||||||
|
w.wrappedLogf("error getting log file info: %v", err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
baseName := filepath.Base(fi.Name())
|
baseName := filepath.Base(fi.Name())
|
||||||
if !strings.HasPrefix(baseName, prefix) {
|
if !strings.HasPrefix(baseName, prefix) {
|
||||||
continue
|
continue
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -248,7 +247,7 @@ func logsDir(logf logger.Logf) string {
|
|||||||
// No idea where to put stuff. Try to create a temp dir. It'll
|
// No idea where to put stuff. Try to create a temp dir. It'll
|
||||||
// mean we might lose some logs and rotate through log IDs, but
|
// mean we might lose some logs and rotate through log IDs, but
|
||||||
// it's something.
|
// it's something.
|
||||||
tmp, err := ioutil.TempDir("", "tailscaled-log-*")
|
tmp, err := os.MkdirTemp("", "tailscaled-log-*")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic("no safe place found to store log state")
|
panic("no safe place found to store log state")
|
||||||
}
|
}
|
||||||
@ -259,7 +258,7 @@ func logsDir(logf logger.Logf) string {
|
|||||||
// runningUnderSystemd reports whether we're running under systemd.
|
// runningUnderSystemd reports whether we're running under systemd.
|
||||||
func runningUnderSystemd() bool {
|
func runningUnderSystemd() bool {
|
||||||
if runtime.GOOS == "linux" && os.Getppid() == 1 {
|
if runtime.GOOS == "linux" && os.Getppid() == 1 {
|
||||||
slurp, _ := ioutil.ReadFile("/proc/1/stat")
|
slurp, _ := os.ReadFile("/proc/1/stat")
|
||||||
return bytes.HasPrefix(slurp, []byte("1 (systemd) "))
|
return bytes.HasPrefix(slurp, []byte("1 (systemd) "))
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
@ -39,7 +39,7 @@ func main() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
b, err := ioutil.ReadAll(resp.Body)
|
b, err := io.ReadAll(resp.Body)
|
||||||
resp.Body.Close()
|
resp.Body.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("logadopt: response read failed %d: %v", resp.StatusCode, err)
|
log.Fatalf("logadopt: response read failed %d: %v", resp.StatusCode, err)
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
"bufio"
|
"bufio"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"flag"
|
"flag"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
@ -50,7 +50,7 @@ func main() {
|
|||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
if resp.StatusCode != 200 {
|
if resp.StatusCode != 200 {
|
||||||
b, err := ioutil.ReadAll(resp.Body)
|
b, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("logreprocess: read error %d: %v", resp.StatusCode, err)
|
log.Fatalf("logreprocess: read error %d: %v", resp.StatusCode, err)
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
@ -195,7 +195,7 @@ func TestFilchStderr(t *testing.T) {
|
|||||||
f.close(t)
|
f.close(t)
|
||||||
|
|
||||||
pipeW.Close()
|
pipeW.Close()
|
||||||
b, err := ioutil.ReadAll(pipeR)
|
b, err := io.ReadAll(pipeR)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,6 @@
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -430,7 +429,7 @@ func (l *Logger) upload(ctx context.Context, body []byte, origlen int) (uploaded
|
|||||||
|
|
||||||
if resp.StatusCode != 200 {
|
if resp.StatusCode != 200 {
|
||||||
uploaded = resp.StatusCode == 400 // the server saved the logs anyway
|
uploaded = resp.StatusCode == 400 // the server saved the logs anyway
|
||||||
b, _ := ioutil.ReadAll(io.LimitReader(resp.Body, 1<<20))
|
b, _ := io.ReadAll(io.LimitReader(resp.Body, 1<<20))
|
||||||
return uploaded, fmt.Errorf("log upload of %d bytes %s failed %d: %q", len(body), compressedNote, resp.StatusCode, b)
|
return uploaded, fmt.Errorf("log upload of %d bytes %s failed %d: %q", len(body), compressedNote, resp.StatusCode, b)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -654,7 +653,7 @@ func (l *Logger) Write(buf []byte) (int, error) {
|
|||||||
return 0, nil
|
return 0, nil
|
||||||
}
|
}
|
||||||
level, buf := parseAndRemoveLogLevel(buf)
|
level, buf := parseAndRemoveLogLevel(buf)
|
||||||
if l.stderr != nil && l.stderr != ioutil.Discard && int64(level) <= atomic.LoadInt64(&l.stderrLevel) {
|
if l.stderr != nil && l.stderr != io.Discard && int64(level) <= atomic.LoadInt64(&l.stderrLevel) {
|
||||||
if buf[len(buf)-1] == '\n' {
|
if buf[len(buf)-1] == '\n' {
|
||||||
l.stderr.Write(buf)
|
l.stderr.Write(buf)
|
||||||
} else {
|
} else {
|
||||||
|
@ -9,7 +9,6 @@
|
|||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"strings"
|
"strings"
|
||||||
@ -52,7 +51,7 @@ func NewLogtailTestHarness(t *testing.T) (*LogtailTestServer, *Logger) {
|
|||||||
|
|
||||||
ts.srv = httptest.NewServer(http.HandlerFunc(
|
ts.srv = httptest.NewServer(http.HandlerFunc(
|
||||||
func(w http.ResponseWriter, r *http.Request) {
|
func(w http.ResponseWriter, r *http.Request) {
|
||||||
body, err := ioutil.ReadAll(r.Body)
|
body, err := io.ReadAll(r.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error("failed to read HTTP request")
|
t.Error("failed to read HTTP request")
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,6 @@
|
|||||||
"bytes"
|
"bytes"
|
||||||
_ "embed"
|
_ "embed"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -158,7 +157,7 @@ func (m *resolvconfManager) GetBaseConfig() (OSConfig, error) {
|
|||||||
if sc.Text() == resolvconfConfigName {
|
if sc.Text() == resolvconfConfigName {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
bs, err := ioutil.ReadFile(filepath.Join(m.interfacesDir, sc.Text()))
|
bs, err := os.ReadFile(filepath.Join(m.interfacesDir, sc.Text()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
// Probably raced with a deletion, that's okay.
|
// Probably raced with a deletion, that's okay.
|
||||||
|
@ -12,7 +12,6 @@
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"io/ioutil"
|
|
||||||
"net/netip"
|
"net/netip"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
@ -452,7 +451,7 @@ func (fs directFS) Rename(oldName, newName string) error {
|
|||||||
func (fs directFS) Remove(name string) error { return os.Remove(fs.path(name)) }
|
func (fs directFS) Remove(name string) error { return os.Remove(fs.path(name)) }
|
||||||
|
|
||||||
func (fs directFS) ReadFile(name string) ([]byte, error) {
|
func (fs directFS) ReadFile(name string) ([]byte, error) {
|
||||||
return ioutil.ReadFile(fs.path(name))
|
return os.ReadFile(fs.path(name))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fs directFS) Truncate(name string) error {
|
func (fs directFS) Truncate(name string) error {
|
||||||
@ -460,7 +459,7 @@ func (fs directFS) Truncate(name string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (fs directFS) WriteFile(name string, contents []byte, perm os.FileMode) error {
|
func (fs directFS) WriteFile(name string, contents []byte, perm os.FileMode) error {
|
||||||
return ioutil.WriteFile(fs.path(name), contents, perm)
|
return os.WriteFile(fs.path(name), contents, perm)
|
||||||
}
|
}
|
||||||
|
|
||||||
// runningAsGUIDesktopUser reports whether it seems that this code is
|
// runningAsGUIDesktopUser reports whether it seems that this code is
|
||||||
|
@ -6,14 +6,13 @@
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"tailscale.com/types/logger"
|
"tailscale.com/types/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewOSConfigurator(logf logger.Logf, _ string) (OSConfigurator, error) {
|
func NewOSConfigurator(logf logger.Logf, _ string) (OSConfigurator, error) {
|
||||||
bs, err := ioutil.ReadFile("/etc/resolv.conf")
|
bs, err := os.ReadFile("/etc/resolv.conf")
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
return newDirectManager(logf), nil
|
return newDirectManager(logf), nil
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,6 @@
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -474,7 +473,7 @@ func (f *forwarder) sendDoH(ctx context.Context, urlBase string, c *http.Client,
|
|||||||
metricDNSFwdDoHErrorCT.Add(1)
|
metricDNSFwdDoHErrorCT.Add(1)
|
||||||
return nil, fmt.Errorf("unexpected response Content-Type %q", ct)
|
return nil, fmt.Errorf("unexpected response Content-Type %q", ct)
|
||||||
}
|
}
|
||||||
res, err := ioutil.ReadAll(hres.Body)
|
res, err := io.ReadAll(hres.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
metricDNSFwdDoHErrorBody.Add(1)
|
metricDNSFwdDoHErrorBody.Add(1)
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,6 @@
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
@ -42,7 +41,7 @@ func main() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
if err := ioutil.WriteFile("dns-fallback-servers.json", out, 0644); err != nil {
|
if err := os.WriteFile("dns-fallback-servers.json", out, 0644); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,6 @@
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
@ -23,7 +22,7 @@ func TestGoogleCloudRunDefaultRouteInterface(t *testing.T) {
|
|||||||
buf := []byte("Iface\tDestination\tGateway\tFlags\tRefCnt\tUse\tMetric\tMask\tMTU\tWindow\tIRTT\n" +
|
buf := []byte("Iface\tDestination\tGateway\tFlags\tRefCnt\tUse\tMetric\tMask\tMTU\tWindow\tIRTT\n" +
|
||||||
"eth0\t8008FEA9\t00000000\t0001\t0\t0\t0\t01FFFFFF\t0\t0\t0\n" +
|
"eth0\t8008FEA9\t00000000\t0001\t0\t0\t0\t01FFFFFF\t0\t0\t0\n" +
|
||||||
"eth1\t00000000\t00000000\t0001\t0\t0\t0\t00000000\t0\t0\t0\n")
|
"eth1\t00000000\t00000000\t0001\t0\t0\t0\t00000000\t0\t0\t0\n")
|
||||||
err := ioutil.WriteFile(procNetRoutePath, buf, 0644)
|
err := os.WriteFile(procNetRoutePath, buf, 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -87,7 +86,7 @@ func TestAwsAppRunnerDefaultRouteInterface(t *testing.T) {
|
|||||||
"ecs-eth0\t02AAFEA9\t01ACFEA9\t0007\t0\t0\t0\tFFFFFFFF\t0\t0\t0\n" +
|
"ecs-eth0\t02AAFEA9\t01ACFEA9\t0007\t0\t0\t0\tFFFFFFFF\t0\t0\t0\n" +
|
||||||
"ecs-eth0\t00ACFEA9\t00000000\t0001\t0\t0\t0\t00FFFFFF\t0\t0\t0\n" +
|
"ecs-eth0\t00ACFEA9\t00000000\t0001\t0\t0\t0\t00FFFFFF\t0\t0\t0\n" +
|
||||||
"eth0\t00AFFEA9\t00000000\t0001\t0\t0\t0\t00FFFFFF\t0\t0\t0\n")
|
"eth0\t00AFFEA9\t00000000\t0001\t0\t0\t0\t00FFFFFF\t0\t0\t0\n")
|
||||||
err := ioutil.WriteFile(procNetRoutePath, buf, 0644)
|
err := os.WriteFile(procNetRoutePath, buf, 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,6 @@
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -1096,7 +1095,7 @@ func (c *Client) measureHTTPSLatency(ctx context.Context, reg *tailcfg.DERPRegio
|
|||||||
return 0, ip, fmt.Errorf("unexpected status code: %d (%s)", resp.StatusCode, resp.Status)
|
return 0, ip, fmt.Errorf("unexpected status code: %d (%s)", resp.StatusCode, resp.Status)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = io.Copy(ioutil.Discard, io.LimitReader(resp.Body, 8<<10))
|
_, err = io.Copy(io.Discard, io.LimitReader(resp.Body, 8<<10))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, ip, err
|
return 0, ip, err
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,6 @@
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
@ -60,7 +59,7 @@ func TestSynologyProxyFromConfigCached(t *testing.T) {
|
|||||||
cache.httpProxy = nil
|
cache.httpProxy = nil
|
||||||
cache.httpsProxy = nil
|
cache.httpsProxy = nil
|
||||||
|
|
||||||
if err := ioutil.WriteFile(synologyProxyConfigPath, []byte(`
|
if err := os.WriteFile(synologyProxyConfigPath, []byte(`
|
||||||
proxy_enabled=yes
|
proxy_enabled=yes
|
||||||
http_host=10.0.0.55
|
http_host=10.0.0.55
|
||||||
http_port=80
|
http_port=80
|
||||||
@ -116,7 +115,7 @@ func TestSynologyProxyFromConfigCached(t *testing.T) {
|
|||||||
cache.httpProxy = nil
|
cache.httpProxy = nil
|
||||||
cache.httpsProxy = nil
|
cache.httpsProxy = nil
|
||||||
|
|
||||||
if err := ioutil.WriteFile(synologyProxyConfigPath, []byte(`
|
if err := os.WriteFile(synologyProxyConfigPath, []byte(`
|
||||||
proxy_enabled=yes
|
proxy_enabled=yes
|
||||||
http_host=10.0.0.55
|
http_host=10.0.0.55
|
||||||
http_port=80
|
http_port=80
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -74,7 +73,7 @@ func Read(r io.Reader) (*Info, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Exhaust the remainder of r, so that the summers see the entire file.
|
// Exhaust the remainder of r, so that the summers see the entire file.
|
||||||
if _, err := io.Copy(ioutil.Discard, r); err != nil {
|
if _, err := io.Copy(io.Discard, r); err != nil {
|
||||||
return nil, fmt.Errorf("hashing file: %w", err)
|
return nil, fmt.Errorf("hashing file: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,7 +116,7 @@ func findControlTar(r io.Reader) (tarReader io.Reader, err error) {
|
|||||||
if size%2 == 1 {
|
if size%2 == 1 {
|
||||||
size++
|
size++
|
||||||
}
|
}
|
||||||
if _, err := io.CopyN(ioutil.Discard, r, size); err != nil {
|
if _, err := io.CopyN(io.Discard, r, size); err != nil {
|
||||||
return nil, fmt.Errorf("seeking past file %q: %w", filename, err)
|
return nil, fmt.Errorf("seeking past file %q: %w", filename, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -150,7 +149,7 @@ func findControlFile(r io.Reader) (control []byte, err error) {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
bs, err := ioutil.ReadAll(tr)
|
bs, err := io.ReadAll(tr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("reading control file: %w", err)
|
return nil, fmt.Errorf("reading control file: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,6 @@
|
|||||||
"bufio"
|
"bufio"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
@ -230,7 +229,7 @@ func addProcesses(pl []Port) ([]Port, error) {
|
|||||||
|
|
||||||
pe := pm[string(targetBuf[:n])] // m[string([]byte)] avoids alloc
|
pe := pm[string(targetBuf[:n])] // m[string([]byte)] avoids alloc
|
||||||
if pe != nil {
|
if pe != nil {
|
||||||
bs, err := ioutil.ReadFile(fmt.Sprintf("/proc/%s/cmdline", pid))
|
bs, err := os.ReadFile(fmt.Sprintf("/proc/%s/cmdline", pid))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Usually shouldn't happen. One possibility is
|
// Usually shouldn't happen. One possibility is
|
||||||
// the process has gone away, so let's skip it.
|
// the process has gone away, so let's skip it.
|
||||||
|
@ -9,7 +9,6 @@
|
|||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -70,7 +69,7 @@ func localTCPPortAndTokenDarwin() (port int, token string, err error) {
|
|||||||
// The current binary (this process) is sandboxed. The user is
|
// The current binary (this process) is sandboxed. The user is
|
||||||
// running the CLI via /Applications/Tailscale.app/Contents/MacOS/Tailscale
|
// running the CLI via /Applications/Tailscale.app/Contents/MacOS/Tailscale
|
||||||
// which sets the TS_MACOS_CLI_SHARED_DIR environment variable.
|
// which sets the TS_MACOS_CLI_SHARED_DIR environment variable.
|
||||||
fis, err := ioutil.ReadDir(dir)
|
fis, err := os.ReadDir(dir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, "", err
|
return 0, "", err
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
package smallzstd
|
package smallzstd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/klauspost/compress/zstd"
|
"github.com/klauspost/compress/zstd"
|
||||||
@ -113,7 +113,7 @@ func benchDecoderWithConstruction(b *testing.B, mk func() (*zstd.Decoder, error)
|
|||||||
|
|
||||||
func testdata(b *testing.B) []byte {
|
func testdata(b *testing.B) []byte {
|
||||||
b.Helper()
|
b.Helper()
|
||||||
in, err := ioutil.ReadFile("testdata")
|
in, err := os.ReadFile("testdata")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Fatalf("reading testdata: %v", err)
|
b.Fatalf("reading testdata: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/netip"
|
"net/netip"
|
||||||
@ -1306,7 +1305,7 @@ func (ss *sshSession) startNewRecording() (*recording, error) {
|
|||||||
if err := os.MkdirAll(dir, 0700); err != nil {
|
if err := os.MkdirAll(dir, 0700); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
f, err := ioutil.TempFile(dir, fmt.Sprintf("ssh-session-%v-*.cast", now.UnixNano()))
|
f, err := os.CreateTemp(dir, fmt.Sprintf("ssh-session-%v-*.cast", now.UnixNano()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"net"
|
"net"
|
||||||
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
@ -36,7 +36,7 @@ func AgentRequested(sess Session) bool {
|
|||||||
// NewAgentListener sets up a temporary Unix socket that can be communicated
|
// NewAgentListener sets up a temporary Unix socket that can be communicated
|
||||||
// to the session environment and used for forwarding connections.
|
// to the session environment and used for forwarding connections.
|
||||||
func NewAgentListener() (net.Listener, error) {
|
func NewAgentListener() (net.Listener, error) {
|
||||||
dir, err := ioutil.TempDir("", agentTempDir)
|
dir, err := os.MkdirTemp("", agentTempDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"os"
|
||||||
|
|
||||||
"tailscale.com/tempfork/gliderlabs/ssh"
|
"tailscale.com/tempfork/gliderlabs/ssh"
|
||||||
)
|
)
|
||||||
@ -29,7 +29,7 @@ func ExampleNoPty() {
|
|||||||
func ExamplePublicKeyAuth() {
|
func ExamplePublicKeyAuth() {
|
||||||
ssh.ListenAndServe(":2222", nil,
|
ssh.ListenAndServe(":2222", nil,
|
||||||
ssh.PublicKeyAuth(func(ctx ssh.Context, key ssh.PublicKey) error {
|
ssh.PublicKeyAuth(func(ctx ssh.Context, key ssh.PublicKey) error {
|
||||||
data, err := ioutil.ReadFile("/path/to/allowed/key.pub")
|
data, err := os.ReadFile("/path/to/allowed/key.pub")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package ssh
|
package ssh
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"os"
|
||||||
|
|
||||||
gossh "github.com/tailscale/golang-x-crypto/ssh"
|
gossh "github.com/tailscale/golang-x-crypto/ssh"
|
||||||
)
|
)
|
||||||
@ -26,7 +26,7 @@ func PublicKeyAuth(fn PublicKeyHandler) Option {
|
|||||||
// from a PEM file at filepath.
|
// from a PEM file at filepath.
|
||||||
func HostKeyFile(filepath string) Option {
|
func HostKeyFile(filepath string) Option {
|
||||||
return func(srv *Server) error {
|
return func(srv *Server) error {
|
||||||
pemBytes, err := ioutil.ReadFile(filepath)
|
pemBytes, err := os.ReadFile(filepath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"io/ioutil"
|
|
||||||
"net"
|
"net"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@ -61,7 +60,7 @@ func TestLocalPortForwardingWorks(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Error connecting to %v: %v", l.Addr().String(), err)
|
t.Fatalf("Error connecting to %v: %v", l.Addr().String(), err)
|
||||||
}
|
}
|
||||||
result, err := ioutil.ReadAll(conn)
|
result, err := io.ReadAll(conn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"runtime/pprof"
|
"runtime/pprof"
|
||||||
@ -52,7 +52,7 @@ func TestHandlers(t *testing.T) {
|
|||||||
t.Errorf("status code: got %d; want %d", got, want)
|
t.Errorf("status code: got %d; want %d", got, want)
|
||||||
}
|
}
|
||||||
|
|
||||||
body, err := ioutil.ReadAll(resp.Body)
|
body, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("when reading response body, expected non-nil err; got %v", err)
|
t.Errorf("when reading response body, expected non-nil err; got %v", err)
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,6 @@
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sync"
|
"sync"
|
||||||
@ -345,7 +344,7 @@ func (c *FS) LastActiveAncestor() (*AUMHash, error) {
|
|||||||
c.mu.RLock()
|
c.mu.RLock()
|
||||||
defer c.mu.RUnlock()
|
defer c.mu.RUnlock()
|
||||||
|
|
||||||
hash, err := ioutil.ReadFile(filepath.Join(c.base, "last_active_ancestor"))
|
hash, err := os.ReadFile(filepath.Join(c.base, "last_active_ancestor"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
return nil, nil // Not exist == none set.
|
return nil, nil // Not exist == none set.
|
||||||
|
@ -11,7 +11,6 @@
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -252,7 +251,7 @@ func (s *Server) start() (reterr error) {
|
|||||||
c := logtail.Config{
|
c := logtail.Config{
|
||||||
Collection: lpc.Collection,
|
Collection: lpc.Collection,
|
||||||
PrivateID: lpc.PrivateID,
|
PrivateID: lpc.PrivateID,
|
||||||
Stderr: ioutil.Discard, // log everything to Buffer
|
Stderr: io.Discard, // log everything to Buffer
|
||||||
Buffer: s.logbuffer,
|
Buffer: s.logbuffer,
|
||||||
NewZstdEncoder: func() logtail.Encoder {
|
NewZstdEncoder: func() logtail.Encoder {
|
||||||
w, err := smallzstd.NewEncoder(nil)
|
w, err := smallzstd.NewEncoder(nil)
|
||||||
|
@ -11,7 +11,6 @@
|
|||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
@ -62,7 +61,7 @@ func generate(goos string) {
|
|||||||
fmt.Fprintf(&out, ")\n")
|
fmt.Fprintf(&out, ")\n")
|
||||||
|
|
||||||
filename := fmt.Sprintf("tailscaled_deps_test_%s.go", goos)
|
filename := fmt.Sprintf("tailscaled_deps_test_%s.go", goos)
|
||||||
err = ioutil.WriteFile(filename, out.Bytes(), 0644)
|
err = os.WriteFile(filename, out.Bytes(), 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,6 @@
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -88,7 +87,7 @@ func TailscaledBinary(tb testing.TB) string {
|
|||||||
// buildTestBinaries builds tailscale and tailscaled.
|
// buildTestBinaries builds tailscale and tailscaled.
|
||||||
// It returns the dir containing the binaries.
|
// It returns the dir containing the binaries.
|
||||||
func buildTestBinaries() (string, error) {
|
func buildTestBinaries() (string, error) {
|
||||||
bindir, err := ioutil.TempDir("", "")
|
bindir, err := os.MkdirTemp("", "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
@ -288,7 +287,7 @@ func (lc *LogCatcher) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
defer dec.Close()
|
defer dec.Close()
|
||||||
body = dec
|
body = dec
|
||||||
}
|
}
|
||||||
bodyBytes, _ := ioutil.ReadAll(body)
|
bodyBytes, _ := io.ReadAll(body)
|
||||||
|
|
||||||
type Entry struct {
|
type Entry struct {
|
||||||
Logtail struct {
|
Logtail struct {
|
||||||
|
@ -14,7 +14,6 @@
|
|||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
@ -653,7 +652,7 @@ func newTestNode(t *testing.T, env *testEnv) *testNode {
|
|||||||
func (n *testNode) diskPrefs() *ipn.Prefs {
|
func (n *testNode) diskPrefs() *ipn.Prefs {
|
||||||
t := n.env.t
|
t := n.env.t
|
||||||
t.Helper()
|
t.Helper()
|
||||||
if _, err := ioutil.ReadFile(n.stateFile); err != nil {
|
if _, err := os.ReadFile(n.stateFile); err != nil {
|
||||||
t.Fatalf("reading prefs: %v", err)
|
t.Fatalf("reading prefs: %v", err)
|
||||||
}
|
}
|
||||||
fs, err := store.NewFileStore(nil, n.stateFile)
|
fs, err := store.NewFileStore(nil, n.stateFile)
|
||||||
@ -768,7 +767,7 @@ func (op *nodeOutputParser) parseLines() {
|
|||||||
if len(buf) == 0 {
|
if len(buf) == 0 {
|
||||||
op.buf.Reset()
|
op.buf.Reset()
|
||||||
} else {
|
} else {
|
||||||
io.CopyN(ioutil.Discard, &op.buf, int64(op.buf.Len()-len(buf)))
|
io.CopyN(io.Discard, &op.buf, int64(op.buf.Len()-len(buf)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,7 +14,6 @@
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -426,7 +425,7 @@ func (s *Server) CompleteAuth(authPathOrURL string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) serveRegister(w http.ResponseWriter, r *http.Request, mkey key.MachinePublic) {
|
func (s *Server) serveRegister(w http.ResponseWriter, r *http.Request, mkey key.MachinePublic) {
|
||||||
msg, err := ioutil.ReadAll(io.LimitReader(r.Body, msgLimit))
|
msg, err := io.ReadAll(io.LimitReader(r.Body, msgLimit))
|
||||||
r.Body.Close()
|
r.Body.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, fmt.Sprintf("bad map request read: %v", err), 400)
|
http.Error(w, fmt.Sprintf("bad map request read: %v", err), 400)
|
||||||
@ -597,7 +596,7 @@ func (s *Server) serveMap(w http.ResponseWriter, r *http.Request, mkey key.Machi
|
|||||||
defer s.incrInServeMap(-1)
|
defer s.incrInServeMap(-1)
|
||||||
ctx := r.Context()
|
ctx := r.Context()
|
||||||
|
|
||||||
msg, err := ioutil.ReadAll(io.LimitReader(r.Body, msgLimit))
|
msg, err := io.ReadAll(io.LimitReader(r.Body, msgLimit))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
r.Body.Close()
|
r.Body.Close()
|
||||||
http.Error(w, fmt.Sprintf("bad map request read: %v", err), 400)
|
http.Error(w, fmt.Sprintf("bad map request read: %v", err), 400)
|
||||||
|
@ -13,7 +13,6 @@
|
|||||||
"expvar"
|
"expvar"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
_ "net/http/pprof"
|
_ "net/http/pprof"
|
||||||
@ -81,7 +80,7 @@ func AllowDebugAccess(r *http.Request) bool {
|
|||||||
urlKey := r.FormValue("debugkey")
|
urlKey := r.FormValue("debugkey")
|
||||||
keyPath := envknob.String("TS_DEBUG_KEY_PATH")
|
keyPath := envknob.String("TS_DEBUG_KEY_PATH")
|
||||||
if urlKey != "" && keyPath != "" {
|
if urlKey != "" && keyPath != "" {
|
||||||
slurp, err := ioutil.ReadFile(keyPath)
|
slurp, err := os.ReadFile(keyPath)
|
||||||
if err == nil && string(bytes.TrimSpace(slurp)) == urlKey {
|
if err == nil && string(bytes.TrimSpace(slurp)) == urlKey {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,6 @@
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
@ -268,7 +267,7 @@ func (fn ArgWriter) Format(f fmt.State, _ rune) {
|
|||||||
argBufioPool.Put(bw)
|
argBufioPool.Put(bw)
|
||||||
}
|
}
|
||||||
|
|
||||||
var argBufioPool = &sync.Pool{New: func() any { return bufio.NewWriterSize(ioutil.Discard, 1024) }}
|
var argBufioPool = &sync.Pool{New: func() any { return bufio.NewWriterSize(io.Discard, 1024) }}
|
||||||
|
|
||||||
// Filtered returns a Logf that silently swallows some log lines.
|
// Filtered returns a Logf that silently swallows some log lines.
|
||||||
// Each inbound format and args is evaluated and printed to a string s.
|
// Each inbound format and args is evaluated and printed to a string s.
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -1174,7 +1174,7 @@ func TestDiscoStringLogRace(t *testing.T) {
|
|||||||
wg.Add(2)
|
wg.Add(2)
|
||||||
go func() {
|
go func() {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
fmt.Fprintf(ioutil.Discard, "%v", de)
|
fmt.Fprintf(io.Discard, "%v", de)
|
||||||
}()
|
}()
|
||||||
go func() {
|
go func() {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
|
@ -8,7 +8,6 @@
|
|||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"net/netip"
|
"net/netip"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
@ -1601,7 +1600,7 @@ func checkIPv6(logf logger.Logf) error {
|
|||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
bs, err := ioutil.ReadFile("/proc/sys/net/ipv6/conf/all/disable_ipv6")
|
bs, err := os.ReadFile("/proc/sys/net/ipv6/conf/all/disable_ipv6")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Be conservative if we can't find the ipv6 configuration knob.
|
// Be conservative if we can't find the ipv6 configuration knob.
|
||||||
return err
|
return err
|
||||||
@ -1617,7 +1616,7 @@ func checkIPv6(logf logger.Logf) error {
|
|||||||
// Older kernels don't support IPv6 policy routing. Some kernels
|
// Older kernels don't support IPv6 policy routing. Some kernels
|
||||||
// support policy routing but don't have this knob, so absence of
|
// support policy routing but don't have this knob, so absence of
|
||||||
// the knob is not fatal.
|
// the knob is not fatal.
|
||||||
bs, err = ioutil.ReadFile("/proc/sys/net/ipv6/conf/all/disable_policy")
|
bs, err = os.ReadFile("/proc/sys/net/ipv6/conf/all/disable_policy")
|
||||||
if err == nil {
|
if err == nil {
|
||||||
disabled, err = strconv.ParseBool(strings.TrimSpace(string(bs)))
|
disabled, err = strconv.ParseBool(strings.TrimSpace(string(bs)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -1647,7 +1646,7 @@ func checkIPv6(logf logger.Logf) error {
|
|||||||
// netfilter, so some older distros ship a kernel that can't NAT IPv6
|
// netfilter, so some older distros ship a kernel that can't NAT IPv6
|
||||||
// traffic.
|
// traffic.
|
||||||
func supportsV6NAT() bool {
|
func supportsV6NAT() bool {
|
||||||
bs, err := ioutil.ReadFile("/proc/net/ip6_tables_names")
|
bs, err := os.ReadFile("/proc/net/ip6_tables_names")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Can't read the file. Assume SNAT works.
|
// Can't read the file. Assume SNAT works.
|
||||||
return true
|
return true
|
||||||
|
Loading…
Reference in New Issue
Block a user