diff --git a/backends/local.go b/backends/local.go index e0dc671..ea9d2e7 100644 --- a/backends/local.go +++ b/backends/local.go @@ -6,6 +6,7 @@ import ( "os" "path/filepath" "strings" + "time" ) type LocalClient struct { @@ -68,11 +69,38 @@ func (c *LocalClient) Writer(path string, opts *WriteOptions) (io.WriteCloser, e return nil, err } - return os.OpenFile( + mode := uint32(0666) + if opts != nil && opts.Mode > 0 { + mode = opts.Mode + } + + f, err := os.OpenFile( path, os.O_WRONLY|os.O_TRUNC|os.O_CREATE, - 0666, + os.FileMode(mode), ) + + if err != nil || opts == nil || opts.Mtime.IsZero() { + return f, err + } + + return &fileWriter{f: f, mtime: opts.Mtime, path: path}, nil } -// err = os.Chtimes(filename, currenttime, currenttime) +type fileWriter struct { + f *os.File + mtime time.Time + path string +} + +func (w *fileWriter) Write(p []byte) (n int, err error) { + return w.f.Write(p) +} + +func (w *fileWriter) Close() error { + err := w.f.Close() + if err != nil { + return err + } + return os.Chtimes(w.path, w.mtime, w.mtime) +} diff --git a/backends/local_test.go b/backends/local_test.go new file mode 100644 index 0000000..d9e23a7 --- /dev/null +++ b/backends/local_test.go @@ -0,0 +1,14 @@ +package backends + +import ( + "github.com/stretchr/testify/suite" + "testing" +) + +type testLocalBackend struct { + suite.Suite +} + +func TestLocalBackendSuite(t *testing.T) { + suite.Run(t, new(testLocalBackend)) +} diff --git a/backends/types.go b/backends/types.go index 45db6a2..3d81698 100644 --- a/backends/types.go +++ b/backends/types.go @@ -13,17 +13,6 @@ import ( const OriginalMtimeKey = "original_mtime" const OriginalModeKey = "original_mode" -type FileSearcher struct { - SourcePath string - TargetPath string - Since time.Time - MinSize int64 - MaxSize int64 - Filter string - Recursive bool - Hidden bool -} - type ListDirTask struct { Source *PathParams Since time.Time