backend: remove dead code

This commit is contained in:
Michael Eischer
2024-08-26 21:16:22 +02:00
parent af989aab4e
commit 97f696b937
5 changed files with 15 additions and 153 deletions

View File

@@ -50,8 +50,6 @@ func NewFactory() location.Factory {
return location.NewLimitedBackendFactory("sftp", ParseConfig, location.NoPassword, limiter.WrapBackendConstructor(Create), limiter.WrapBackendConstructor(Open))
}
const defaultLayout = "default"
func startClient(cfg Config) (*SFTP, error) {
program, args, err := buildSSHCommand(cfg)
if err != nil {
@@ -145,7 +143,7 @@ func (r *SFTP) clientError() error {
// Open opens an sftp backend as described by the config by running
// "ssh" with the appropriate arguments (or cfg.Command, if set).
func Open(ctx context.Context, cfg Config) (*SFTP, error) {
func Open(_ context.Context, cfg Config) (*SFTP, error) {
debug.Log("open backend with config %#v", cfg)
sftp, err := startClient(cfg)
@@ -154,10 +152,10 @@ func Open(ctx context.Context, cfg Config) (*SFTP, error) {
return nil, err
}
return open(ctx, sftp, cfg)
return open(sftp, cfg)
}
func open(ctx context.Context, sftp *SFTP, cfg Config) (*SFTP, error) {
func open(sftp *SFTP, cfg Config) (*SFTP, error) {
fi, err := sftp.c.Stat(sftp.Layout.Filename(backend.Handle{Type: backend.ConfigFile}))
m := util.DeriveModesFromFileInfo(fi, err)
debug.Log("using (%03O file, %03O dir) permissions", m.File, m.Dir)
@@ -193,16 +191,6 @@ func (r *SFTP) mkdirAllDataSubdirs(ctx context.Context, nconn uint) error {
return g.Wait()
}
// ReadDir returns the entries for a directory.
func (r *SFTP) ReadDir(_ context.Context, dir string) ([]os.FileInfo, error) {
fi, err := r.c.ReadDir(dir)
// sftp client does not specify dir name on error, so add it here
err = errors.Wrapf(err, "(%v)", dir)
return fi, err
}
// IsNotExist returns true if the error is caused by a not existing file.
func (r *SFTP) IsNotExist(err error) bool {
return errors.Is(err, os.ErrNotExist)
@@ -273,7 +261,7 @@ func Create(ctx context.Context, cfg Config) (*SFTP, error) {
}
// repurpose existing connection
return open(ctx, sftp, cfg)
return open(sftp, cfg)
}
func (r *SFTP) Connections() uint {
@@ -290,12 +278,6 @@ func (r *SFTP) HasAtomicReplace() bool {
return r.posixRename
}
// Join joins the given paths and cleans them afterwards. This always uses
// forward slashes, which is required by sftp.
func Join(parts ...string) string {
return path.Clean(path.Join(parts...))
}
// tempSuffix generates a random string suffix that should be sufficiently long
// to avoid accidental conflicts
func tempSuffix() string {
@@ -560,9 +542,9 @@ func (r *SFTP) Close() error {
}
func (r *SFTP) deleteRecursive(ctx context.Context, name string) error {
entries, err := r.ReadDir(ctx, name)
entries, err := r.c.ReadDir(name)
if err != nil {
return errors.Wrap(err, "ReadDir")
return errors.Wrapf(err, "ReadDir(%v)", name)
}
for _, fi := range entries {