From d8df353ce884c1de6f97d8aa905abbfb4e699009 Mon Sep 17 00:00:00 2001 From: Matthew Penner Date: Mon, 15 Nov 2021 10:24:52 -0700 Subject: [PATCH] replace deprecated ioutil function calls --- cmd/configure.go | 24 ++++--- cmd/diagnostics.go | 26 ++++---- config/config.go | 7 +- go.mod | 97 ++++++++++++++++++++-------- parser/helpers.go | 6 +- parser/parser.go | 10 ++- remote/http.go | 5 +- server/backup.go | 3 +- server/filesystem/compress_test.go | 5 +- server/filesystem/filesystem_test.go | 17 +++-- server/manager.go | 5 +- sftp/handler.go | 7 +- sftp/server.go | 9 ++- sftp/utils.go | 10 +-- 14 files changed, 130 insertions(+), 101 deletions(-) diff --git a/cmd/configure.go b/cmd/configure.go index 1c0f45c..978615f 100644 --- a/cmd/configure.go +++ b/cmd/configure.go @@ -4,7 +4,7 @@ import ( "crypto/tls" "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "net/url" "os" @@ -19,16 +19,14 @@ import ( "github.com/pterodactyl/wings/config" ) -var ( - configureArgs struct { - PanelURL string - Token string - ConfigPath string - Node string - Override bool - AllowInsecure bool - } -) +var configureArgs struct { + PanelURL string + Token string + ConfigPath string + Node string + Override bool + AllowInsecure bool +} var nodeIdRegex = regexp.MustCompile(`^(\d+)$`) @@ -140,13 +138,13 @@ func configureCmdRun(cmd *cobra.Command, args []string) { fmt.Println("The authentication credentials provided were not valid.") os.Exit(1) } else if res.StatusCode != http.StatusOK { - b, _ := ioutil.ReadAll(res.Body) + b, _ := io.ReadAll(res.Body) fmt.Println("An error occurred while processing this request.\n", string(b)) os.Exit(1) } - b, err := ioutil.ReadAll(res.Body) + b, err := io.ReadAll(res.Body) cfg, err := config.NewAtPath(configPath) if err != nil { diff --git a/cmd/diagnostics.go b/cmd/diagnostics.go index ea847fb..4c5dcc5 100644 --- a/cmd/diagnostics.go +++ b/cmd/diagnostics.go @@ -6,7 +6,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "net/http" "net/url" "os/exec" @@ -29,19 +28,19 @@ import ( "github.com/pterodactyl/wings/system" ) -const DefaultHastebinUrl = "https://ptero.co" -const DefaultLogLines = 200 - -var ( - diagnosticsArgs struct { - IncludeEndpoints bool - IncludeLogs bool - ReviewBeforeUpload bool - HastebinURL string - LogLines int - } +const ( + DefaultHastebinUrl = "https://ptero.co" + DefaultLogLines = 200 ) +var diagnosticsArgs struct { + IncludeEndpoints bool + IncludeLogs bool + ReviewBeforeUpload bool + HastebinURL string + LogLines int +} + func newDiagnosticsCommand() *cobra.Command { command := &cobra.Command{ Use: "diagnostics", @@ -110,7 +109,6 @@ func diagnosticsCmdRun(cmd *cobra.Command, args []string) { printHeader(output, "Wings Configuration") if err := config.FromFile(config.DefaultLocation); err != nil { - } cfg := config.Get() fmt.Fprintln(output, " Panel Location:", redact(cfg.PanelLocation)) @@ -226,7 +224,7 @@ func uploadToHastebin(hbUrl, content string) (string, error) { return "", err } pres := make(map[string]interface{}) - body, err := ioutil.ReadAll(res.Body) + body, err := io.ReadAll(res.Body) if err != nil { fmt.Println("Failed to parse response.", err) return "", err diff --git a/config/config.go b/config/config.go index a75befb..997d4bc 100644 --- a/config/config.go +++ b/config/config.go @@ -4,7 +4,6 @@ import ( "context" "crypto/tls" "fmt" - "io/ioutil" "os" "os/exec" "os/user" @@ -380,7 +379,7 @@ func WriteToDisk(c *Configuration) error { if err != nil { return err } - if err := ioutil.WriteFile(c.path, b, 0o600); err != nil { + if err := os.WriteFile(c.path, b, 0o600); err != nil { return err } return nil @@ -448,7 +447,7 @@ func EnsurePterodactylUser() error { // FromFile reads the configuration from the provided file and stores it in the // global singleton for this instance. func FromFile(path string) error { - b, err := ioutil.ReadFile(path) + b, err := os.ReadFile(path) if err != nil { return err } @@ -592,7 +591,7 @@ func ConfigureTimezone() error { _config.System.Timezone = tz } if _config.System.Timezone == "" { - b, err := ioutil.ReadFile("/etc/timezone") + b, err := os.ReadFile("/etc/timezone") if err != nil { if !os.IsNotExist(err) { return errors.WithMessage(err, "config: failed to open timezone file") diff --git a/go.mod b/go.mod index c303bc1..c597687 100644 --- a/go.mod +++ b/go.mod @@ -1,22 +1,18 @@ module github.com/pterodactyl/wings -go 1.16 +go 1.17 require ( emperror.dev/errors v0.8.0 github.com/AlecAivazis/survey/v2 v2.2.15 github.com/Jeffail/gabs/v2 v2.6.1 - github.com/Microsoft/go-winio v0.5.0 // indirect - github.com/Microsoft/hcsshim v0.8.20 // indirect github.com/NYTimes/logrotate v1.0.0 - github.com/andybalholm/brotli v1.0.3 // indirect github.com/apex/log v1.9.0 github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d github.com/beevik/etree v1.1.0 github.com/buger/jsonparser v1.1.1 github.com/cenkalti/backoff/v4 v4.1.1 github.com/cobaugh/osrelease v0.0.0-20181218015638-a93a0a55a249 - github.com/containerd/containerd v1.5.5 // indirect github.com/creasty/defaults v1.5.1 github.com/docker/docker v20.10.7+incompatible github.com/docker/go-connections v0.4.0 @@ -26,47 +22,94 @@ require ( github.com/gammazero/workerpool v1.1.2 github.com/gbrlsnchs/jwt/v3 v3.0.1 github.com/gin-gonic/gin v1.7.2 - github.com/go-playground/validator/v10 v10.8.0 // indirect - github.com/golang/snappy v0.0.4 // indirect github.com/google/uuid v1.3.0 - github.com/gorilla/mux v1.7.4 // indirect github.com/gorilla/websocket v1.4.2 github.com/iancoleman/strcase v0.2.0 github.com/icza/dyno v0.0.0-20210726202311-f1bafe5d9996 github.com/juju/ratelimit v1.0.1 github.com/karrick/godirwalk v1.16.1 - github.com/klauspost/compress v1.13.2 // indirect github.com/klauspost/pgzip v1.2.5 - github.com/magefile/mage v1.11.0 // indirect github.com/magiconair/properties v1.8.5 github.com/mattn/go-colorable v0.1.8 - github.com/mattn/go-isatty v0.0.13 // indirect - github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect github.com/mholt/archiver/v3 v3.5.0 github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db - github.com/moby/term v0.0.0-20210619224110-3f7ff695adc6 // indirect - github.com/morikuni/aec v1.0.0 // indirect - github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect - github.com/nwaples/rardecode v1.1.1 // indirect github.com/patrickmn/go-cache v2.1.0+incompatible - github.com/pierrec/lz4/v4 v4.1.8 // indirect github.com/pkg/profile v1.6.0 github.com/pkg/sftp v1.13.2 - github.com/prometheus/common v0.30.0 // indirect - github.com/prometheus/procfs v0.7.1 // indirect github.com/sabhiram/go-gitignore v0.0.0-20201211210132-54b8a0bf510f github.com/spf13/cobra v1.2.1 github.com/stretchr/testify v1.7.0 - github.com/ulikunitz/xz v0.5.10 // indirect - go.uber.org/atomic v1.9.0 // indirect - go.uber.org/multierr v1.7.0 // indirect golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97 - golang.org/x/net v0.0.0-20210726213435-c6fcb2dbf985 // indirect golang.org/x/sync v0.0.0-20210220032951-036812b2e83c - golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b // indirect - golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect - google.golang.org/genproto v0.0.0-20210729151513-df9385d47c1b // indirect - gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect gopkg.in/ini.v1 v1.62.0 gopkg.in/yaml.v2 v2.4.0 ) + +require ( + github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect + github.com/Microsoft/go-winio v0.5.0 // indirect + github.com/Microsoft/hcsshim v0.8.20 // indirect + github.com/andybalholm/brotli v1.0.3 // indirect + github.com/beorn7/perks v1.0.1 // indirect + github.com/cespare/xxhash/v2 v2.1.1 // indirect + github.com/containerd/containerd v1.5.5 // indirect + github.com/containerd/fifo v1.0.0 // indirect + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/docker/distribution v2.7.1+incompatible // indirect + github.com/docker/go-metrics v0.0.1 // indirect + github.com/docker/go-units v0.4.0 // indirect + github.com/dsnet/compress v0.0.1 // indirect + github.com/fsnotify/fsnotify v1.4.9 // indirect + github.com/gammazero/deque v0.1.0 // indirect + github.com/gin-contrib/sse v0.1.0 // indirect + github.com/go-playground/locales v0.13.0 // indirect + github.com/go-playground/universal-translator v0.17.0 // indirect + github.com/go-playground/validator/v10 v10.8.0 // indirect + github.com/gogo/protobuf v1.3.2 // indirect + github.com/golang/protobuf v1.5.2 // indirect + github.com/golang/snappy v0.0.4 // indirect + github.com/gorilla/mux v1.7.4 // indirect + github.com/inconshreveable/mousetrap v1.0.0 // indirect + github.com/json-iterator/go v1.1.11 // indirect + github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect + github.com/klauspost/compress v1.13.2 // indirect + github.com/kr/fs v0.1.0 // indirect + github.com/leodido/go-urn v1.2.1 // indirect + github.com/magefile/mage v1.11.0 // indirect + github.com/mattn/go-isatty v0.0.13 // indirect + github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect + github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect + github.com/moby/term v0.0.0-20210619224110-3f7ff695adc6 // indirect + github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect + github.com/modern-go/reflect2 v1.0.1 // indirect + github.com/morikuni/aec v1.0.0 // indirect + github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect + github.com/nwaples/rardecode v1.1.1 // indirect + github.com/opencontainers/go-digest v1.0.0 // indirect + github.com/opencontainers/image-spec v1.0.1 // indirect + github.com/pierrec/lz4/v4 v4.1.8 // indirect + github.com/pkg/errors v0.9.1 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/prometheus/client_golang v1.11.0 // indirect + github.com/prometheus/client_model v0.2.0 // indirect + github.com/prometheus/common v0.30.0 // indirect + github.com/prometheus/procfs v0.7.1 // indirect + github.com/sirupsen/logrus v1.8.1 // indirect + github.com/spf13/pflag v1.0.5 // indirect + github.com/ugorji/go/codec v1.1.7 // indirect + github.com/ulikunitz/xz v0.5.10 // indirect + github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect + go.uber.org/atomic v1.9.0 // indirect + go.uber.org/multierr v1.7.0 // indirect + golang.org/x/net v0.0.0-20210726213435-c6fcb2dbf985 // indirect + golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect + golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b // indirect + golang.org/x/text v0.3.6 // indirect + golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect + golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect + google.golang.org/genproto v0.0.0-20210729151513-df9385d47c1b // indirect + google.golang.org/grpc v1.39.0 // indirect + google.golang.org/protobuf v1.27.1 // indirect + gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect + gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect +) diff --git a/parser/helpers.go b/parser/helpers.go index b5feb52..a8e8ec7 100644 --- a/parser/helpers.go +++ b/parser/helpers.go @@ -2,7 +2,7 @@ package parser import ( "bytes" - "io/ioutil" + "io" "os" "regexp" "strconv" @@ -38,13 +38,13 @@ var xmlValueMatchRegex = regexp.MustCompile(`^\[([\w]+)='(.*)'\]$`) // Gets the []byte representation of a configuration file to be passed through to other // handler functions. If the file does not currently exist, it will be created. func readFileBytes(path string) ([]byte, error) { - file, err := os.OpenFile(path, os.O_CREATE|os.O_RDWR, 0644) + file, err := os.OpenFile(path, os.O_CREATE|os.O_RDWR, 0o644) if err != nil { return nil, err } defer file.Close() - return ioutil.ReadAll(file) + return io.ReadAll(file) } // Gets the value of a key based on the value type defined. diff --git a/parser/parser.go b/parser/parser.go index 44ee7d4..577abc2 100644 --- a/parser/parser.go +++ b/parser/parser.go @@ -3,7 +3,6 @@ package parser import ( "bufio" "encoding/json" - "io/ioutil" "os" "path/filepath" "strconv" @@ -357,7 +356,6 @@ func (f *ConfigurationFile) parseIniFile(path string) error { } } path = append(path, string(v)) - // path := strings.SplitN(replacement.Match, ".", 2) value, err := f.LookupConfigurationValue(replacement) if err != nil { @@ -410,7 +408,7 @@ func (f *ConfigurationFile) parseJsonFile(path string) error { } output := []byte(data.StringIndent("", " ")) - return ioutil.WriteFile(path, output, 0o644) + return os.WriteFile(path, output, 0o644) } // Parses a yaml file and updates any matching key/value pairs before persisting @@ -447,14 +445,14 @@ func (f *ConfigurationFile) parseYamlFile(path string) error { return err } - return ioutil.WriteFile(path, marshaled, 0o644) + return os.WriteFile(path, marshaled, 0o644) } // Parses a text file using basic find and replace. This is a highly inefficient method of // scanning a file and performing a replacement. You should attempt to use anything other // than this function where possible. func (f *ConfigurationFile) parseTextFile(path string) error { - input, err := ioutil.ReadFile(path) + input, err := os.ReadFile(path) if err != nil { return err } @@ -472,7 +470,7 @@ func (f *ConfigurationFile) parseTextFile(path string) error { } } - if err := ioutil.WriteFile(path, []byte(strings.Join(lines, "\n")), 0o644); err != nil { + if err := os.WriteFile(path, []byte(strings.Join(lines, "\n")), 0o644); err != nil { return err } diff --git a/remote/http.go b/remote/http.go index f3ebae2..1229de2 100644 --- a/remote/http.go +++ b/remote/http.go @@ -6,7 +6,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "net/http" "strconv" "strings" @@ -224,9 +223,9 @@ func (r *Response) Read() ([]byte, error) { return nil, errors.New("remote: attempting to read missing response") } if r.Response.Body != nil { - b, _ = ioutil.ReadAll(r.Response.Body) + b, _ = io.ReadAll(r.Response.Body) } - r.Response.Body = ioutil.NopCloser(bytes.NewBuffer(b)) + r.Response.Body = io.NopCloser(bytes.NewBuffer(b)) return b, nil } diff --git a/server/backup.go b/server/backup.go index f511634..a35ccda 100644 --- a/server/backup.go +++ b/server/backup.go @@ -3,7 +3,6 @@ package server import ( "io" "io/fs" - "io/ioutil" "os" "time" @@ -49,7 +48,7 @@ func (s *Server) getServerwideIgnoredFiles() (string, error) { // Don't read a symlinked ignore file, or a file larger than 32KiB in size. return "", nil } - b, err := ioutil.ReadAll(f) + b, err := io.ReadAll(f) if err != nil { return "", err } diff --git a/server/filesystem/compress_test.go b/server/filesystem/compress_test.go index 35ca767..24133a3 100644 --- a/server/filesystem/compress_test.go +++ b/server/filesystem/compress_test.go @@ -1,7 +1,7 @@ package filesystem import ( - "io/ioutil" + "os" "sync/atomic" "testing" @@ -19,11 +19,10 @@ func TestFilesystem_DecompressFile(t *testing.T) { fs, rfs := NewFs() g.Describe("Decompress", func() { - for _, ext := range []string{"zip", "rar", "tar", "tar.gz"} { g.It("can decompress a "+ext, func() { // copy the file to the new FS - c, err := ioutil.ReadFile("./testdata/test." + ext) + c, err := os.ReadFile("./testdata/test." + ext) g.Assert(err).IsNil() err = rfs.CreateServerFile("./test."+ext, c) g.Assert(err).IsNil() diff --git a/server/filesystem/filesystem_test.go b/server/filesystem/filesystem_test.go index 53c2554..43c2cc2 100644 --- a/server/filesystem/filesystem_test.go +++ b/server/filesystem/filesystem_test.go @@ -3,7 +3,6 @@ package filesystem import ( "bytes" "errors" - "io/ioutil" "math/rand" "os" "path/filepath" @@ -25,7 +24,7 @@ func NewFs() (*Filesystem, *rootFs) { }, }) - tmpDir, err := ioutil.TempDir(os.TempDir(), "pterodactyl") + tmpDir, err := os.MkdirTemp(os.TempDir(), "pterodactyl") if err != nil { panic(err) } @@ -71,7 +70,7 @@ func (rfs *rootFs) reset() { } } - if err := os.Mkdir(filepath.Join(rfs.root, "/server"), 0755); err != nil { + if err := os.Mkdir(filepath.Join(rfs.root, "/server"), 0o755); err != nil { panic(err) } } @@ -99,7 +98,7 @@ func TestFilesystem_Readfile(t *testing.T) { }) g.It("returns an error if the \"file\" is a directory", func() { - err := os.Mkdir(filepath.Join(rfs.root, "/server/test.txt"), 0755) + err := os.Mkdir(filepath.Join(rfs.root, "/server/test.txt"), 0o755) g.Assert(err).IsNil() err = fs.Readfile("test.txt", buf) @@ -341,7 +340,7 @@ func TestFilesystem_Rename(t *testing.T) { }) g.It("allows a folder to be renamed", func() { - err := os.Mkdir(filepath.Join(rfs.root, "/server/source_dir"), 0755) + err := os.Mkdir(filepath.Join(rfs.root, "/server/source_dir"), 0o755) g.Assert(err).IsNil() err = fs.Rename("source_dir", "target_dir") @@ -405,7 +404,7 @@ func TestFilesystem_Copy(t *testing.T) { }) g.It("should return an error if the source directory is outside the root", func() { - err := os.MkdirAll(filepath.Join(rfs.root, "/nested/in/dir"), 0755) + err := os.MkdirAll(filepath.Join(rfs.root, "/nested/in/dir"), 0o755) g.Assert(err).IsNil() err = rfs.CreateServerFileFromString("/../nested/in/dir/ext-source.txt", "external content") @@ -421,7 +420,7 @@ func TestFilesystem_Copy(t *testing.T) { }) g.It("should return an error if the source is a directory", func() { - err := os.Mkdir(filepath.Join(rfs.root, "/server/dir"), 0755) + err := os.Mkdir(filepath.Join(rfs.root, "/server/dir"), 0o755) g.Assert(err).IsNil() err = fs.Copy("dir") @@ -466,7 +465,7 @@ func TestFilesystem_Copy(t *testing.T) { }) g.It("should create a copy inside of a directory", func() { - err := os.MkdirAll(filepath.Join(rfs.root, "/server/nested/in/dir"), 0755) + err := os.MkdirAll(filepath.Join(rfs.root, "/server/nested/in/dir"), 0o755) g.Assert(err).IsNil() err = rfs.CreateServerFileFromString("nested/in/dir/source.txt", "test content") @@ -545,7 +544,7 @@ func TestFilesystem_Delete(t *testing.T) { "foo/bar/baz/source.txt", } - err := os.MkdirAll(filepath.Join(rfs.root, "/server/foo/bar/baz"), 0755) + err := os.MkdirAll(filepath.Join(rfs.root, "/server/foo/bar/baz"), 0o755) g.Assert(err).IsNil() for _, s := range sources { diff --git a/server/manager.go b/server/manager.go index 6df09ab..0cd50fd 100644 --- a/server/manager.go +++ b/server/manager.go @@ -5,7 +5,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "os" "path/filepath" "runtime" @@ -137,7 +136,7 @@ func (m *Manager) PersistStates() error { if err != nil { return errors.WithStack(err) } - if err := ioutil.WriteFile(config.Get().System.GetStatesPath(), data, 0644); err != nil { + if err := os.WriteFile(config.Get().System.GetStatesPath(), data, 0o644); err != nil { return errors.WithStack(err) } return nil @@ -145,7 +144,7 @@ func (m *Manager) PersistStates() error { // ReadStates returns the state of the servers. func (m *Manager) ReadStates() (map[string]string, error) { - f, err := os.OpenFile(config.Get().System.GetStatesPath(), os.O_RDONLY|os.O_CREATE, 0644) + f, err := os.OpenFile(config.Get().System.GetStatesPath(), os.O_RDONLY|os.O_CREATE, 0o644) if err != nil { return nil, errors.WithStack(err) } diff --git a/sftp/handler.go b/sftp/handler.go index 2f3f0b9..aeba53c 100644 --- a/sftp/handler.go +++ b/sftp/handler.go @@ -142,12 +142,12 @@ func (h *Handler) Filecmd(request *sftp.Request) error { } mode := request.Attributes().FileMode().Perm() // If the client passes an invalid FileMode just use the default 0644. - if mode == 0000 { - mode = os.FileMode(0644) + if mode == 0o000 { + mode = os.FileMode(0o644) } // Force directories to be 0755. if request.Attributes().FileMode().IsDir() { - mode = 0755 + mode = 0o755 } if err := h.fs.Chmod(request.Filepath, mode); err != nil { if errors.Is(err, os.ErrNotExist) { @@ -260,7 +260,6 @@ func (h *Handler) Filelist(request *sftp.Request) (sftp.ListerAt, error) { files, err := ioutil.ReadDir(p) if err != nil { h.logger.WithField("source", request.Filepath).WithField("error", err).Error("error while listing directory") - return nil, sftp.ErrSSHFxFailure } return ListerAt(files), nil diff --git a/sftp/server.go b/sftp/server.go index df4229e..8a7a194 100644 --- a/sftp/server.go +++ b/sftp/server.go @@ -6,7 +6,6 @@ import ( "crypto/x509" "encoding/pem" "io" - "io/ioutil" "net" "os" "path" @@ -59,7 +58,7 @@ func (c *SFTPServer) Run() error { } else if err != nil { return errors.Wrap(err, "sftp: could not stat private key file") } - pb, err := ioutil.ReadFile(c.PrivateKeyPath()) + pb, err := os.ReadFile(c.PrivateKeyPath()) if err != nil { return errors.Wrap(err, "sftp: could not read private key file") } @@ -159,10 +158,10 @@ func (c *SFTPServer) generateED25519PrivateKey() error { if err != nil { return errors.Wrap(err, "sftp: failed to generate ED25519 private key") } - if err := os.MkdirAll(path.Dir(c.PrivateKeyPath()), 0755); err != nil { + if err := os.MkdirAll(path.Dir(c.PrivateKeyPath()), 0o755); err != nil { return errors.Wrap(err, "sftp: could not create internal sftp data directory") } - o, err := os.OpenFile(c.PrivateKeyPath(), os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600) + o, err := os.OpenFile(c.PrivateKeyPath(), os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0o600) if err != nil { return errors.WithStack(err) } @@ -221,4 +220,4 @@ func (c *SFTPServer) passwordCallback(conn ssh.ConnMetadata, pass []byte) (*ssh. // PrivateKeyPath returns the path the host private key for this server instance. func (c *SFTPServer) PrivateKeyPath() string { return path.Join(c.BasePath, ".sftp/id_ed25519") -} \ No newline at end of file +} diff --git a/sftp/utils.go b/sftp/utils.go index 5dad454..8829501 100644 --- a/sftp/utils.go +++ b/sftp/utils.go @@ -6,15 +6,15 @@ import ( ) const ( - // Extends the default SFTP server to return a quota exceeded error to the client. + // ErrSSHQuotaExceeded extends the default SFTP server to return a quota exceeded error to the client. // // @see https://tools.ietf.org/id/draft-ietf-secsh-filexfer-13.txt - ErrSSHQuotaExceeded = fxerr(15) + ErrSSHQuotaExceeded = fxErr(15) ) type ListerAt []os.FileInfo -// Returns the number of entries copied and an io.EOF error if we made it to the end of the file list. +// ListAt returns the number of entries copied and an io.EOF error if we made it to the end of the file list. // Take a look at the pkg/sftp godoc for more information about how this function should work. func (l ListerAt) ListAt(f []os.FileInfo, offset int64) (int, error) { if offset >= int64(len(l)) { @@ -28,9 +28,9 @@ func (l ListerAt) ListAt(f []os.FileInfo, offset int64) (int, error) { } } -type fxerr uint32 +type fxErr uint32 -func (e fxerr) Error() string { +func (e fxErr) Error() string { switch e { case ErrSSHQuotaExceeded: return "Quota Exceeded"