replace deprecated ioutil function calls
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user