From 23defac759a72e2297e5a120c5e9c28d8fbc7030 Mon Sep 17 00:00:00 2001 From: Jason Bornstein <131717043+jasonbornsteinMOOV@users.noreply.github.com> Date: Tue, 1 Aug 2023 10:04:25 -0400 Subject: [PATCH] remove FTPFileDriver --- pkg/response/file_writer.go | 30 +++++------------------------- pkg/response/file_writer_test.go | 2 +- 2 files changed, 6 insertions(+), 26 deletions(-) diff --git a/pkg/response/file_writer.go b/pkg/response/file_writer.go index 4f3e7ae4..00f65d1b 100644 --- a/pkg/response/file_writer.go +++ b/pkg/response/file_writer.go @@ -2,7 +2,6 @@ package response import ( "bytes" - "errors" "fmt" "io" "os" @@ -23,18 +22,11 @@ type FileWriter interface { func NewFileWriter(logger log.Logger, cfg service.ServerConfig, ftpServer *ftp.Server) FileWriter { if cfg.FTP != nil { - driver, err := ftpServer.Factory.NewDriver() - if err != nil { - return nil // fmt.Errorf("get driver to write: %v", err) - } return &FTPFileWriter{ cfg: cfg.FTP.Paths, rootPath: cfg.FTP.RootPath, logger: logger, server: ftpServer, - driver: FTPFileDriver{ - Driver: driver, - }, } } return nil @@ -45,21 +37,6 @@ type FTPFileWriter struct { rootPath string logger log.Logger server *ftp.Server - driver FTPFileDriver -} - -type FTPFileDriver struct { - ftp.Driver -} - -func (d *FTPFileDriver) ListDir(path string, callback func(ftp.FileInfo) error) error { - return d.Driver.ListDir(path, func(f ftp.FileInfo) error { - if f.ModTime().After(time.Now()) { - // TODO JB: test and see if this actually works - return errors.New("file is in the future") - } - return nil - }) } func (w *FTPFileWriter) WriteFile(filepath string, file *ach.File, futureDated *time.Duration) error { @@ -72,7 +49,10 @@ func (w *FTPFileWriter) WriteFile(filepath string, file *ach.File, futureDated * } func (w *FTPFileWriter) Write(path string, r io.Reader, futureDated *time.Duration) error { - driver := w.driver + driver, err := w.server.Factory.NewDriver() + if err != nil { + return fmt.Errorf("get driver to write %s: %v", path, err) + } if err := mkdir(driver, path); err != nil { return fmt.Errorf("mkdir: %s: %v", path, err) @@ -91,7 +71,7 @@ func (w *FTPFileWriter) Write(path string, r io.Reader, futureDated *time.Durati return nil } -func mkdir(driver FTPFileDriver, path string) error { +func mkdir(driver ftp.Driver, path string) error { dir, _ := filepath.Split(path) return driver.MakeDir(dir) } diff --git a/pkg/response/file_writer_test.go b/pkg/response/file_writer_test.go index 2bfcf206..203b8a5a 100644 --- a/pkg/response/file_writer_test.go +++ b/pkg/response/file_writer_test.go @@ -19,7 +19,7 @@ func TestFileWriter__mkdir(t *testing.T) { path := filepath.Join("foo", "Bar", "baz", "example.ach") - err = mkdir(FTPFileDriver{Driver: driver}, path) + err = mkdir(driver, path) require.NoError(t, err) // Check that the directory exists