Skip to content

Commit

Permalink
remove FTPFileDriver
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonbornsteinMOOV committed Aug 1, 2023
1 parent 33a32c1 commit 23defac
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 26 deletions.
30 changes: 5 additions & 25 deletions pkg/response/file_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package response

import (
"bytes"
"errors"
"fmt"
"io"
"os"
Expand All @@ -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
Expand All @@ -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 {
Expand All @@ -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)
Expand All @@ -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)
}
2 changes: 1 addition & 1 deletion pkg/response/file_writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 23defac

Please sign in to comment.