Skip to content

Commit

Permalink
prep for metadata (mtime/mode) copy
Browse files Browse the repository at this point in the history
  • Loading branch information
yaronha committed May 11, 2019
1 parent 339cfb2 commit ff7b6a4
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 14 deletions.
34 changes: 31 additions & 3 deletions backends/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"
"path/filepath"
"strings"
"time"
)

type LocalClient struct {
Expand Down Expand Up @@ -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)
}
14 changes: 14 additions & 0 deletions backends/local_test.go
Original file line number Diff line number Diff line change
@@ -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))
}
11 changes: 0 additions & 11 deletions backends/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ff7b6a4

Please sign in to comment.