Skip to content

Commit

Permalink
filedrive: wrap ListDir to exclude future dated files
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdecaf committed Jul 31, 2023
1 parent 277a9c0 commit 2011798
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
36 changes: 36 additions & 0 deletions pkg/filedrive/mtime_filter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package filedrive

import (
"time"

"goftp.io/server/core"
)

type MTimeFilter struct {
core.Driver
}

func (mtf MTimeFilter) ListDir(path string, callback func(core.FileInfo) error) error {
now := time.Now()

return mtf.Driver.ListDir(path, func(info core.FileInfo) error {
if info.ModTime().Before(now) {
return callback(info)
}
return nil
})
}

type Factory struct {
DriverFactory core.DriverFactory
}

func (f *Factory) NewDriver() (core.Driver, error) {
dd, err := f.DriverFactory.NewDriver()
if err != nil {
return nil, err
}
return MTimeFilter{
Driver: dd,
}, nil
}
8 changes: 6 additions & 2 deletions pkg/service/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"path/filepath"

_ "github.com/moov-io/ach-test-harness"
"github.com/moov-io/ach-test-harness/pkg/filedrive"
"github.com/moov-io/base/admin"
"github.com/moov-io/base/log"

Expand Down Expand Up @@ -42,12 +43,15 @@ func bootFTPServer(errs chan<- error, logger log.Logger, cfg *FTPConfig, respons
createDataDirectories(errs, logger, cfg)

// Start the FTP server
fileDriver := &file.DriverFactory{
fileDriverFactory := &file.DriverFactory{
RootPath: cfg.RootPath,
Perm: ftp.NewSimplePerm("user", "group"),
}
filteringDriver := &filedrive.Factory{
DriverFactory: fileDriverFactory,
}
opts := &ftp.ServerOpts{
Factory: fileDriver,
Factory: filteringDriver,
Port: cfg.Port,
Hostname: cfg.Hostname,
Auth: &ftp.SimpleAuth{
Expand Down

0 comments on commit 2011798

Please sign in to comment.