Repository navigation
Expand file tree
/
Copy pathdir_wrapper.go
More file actions
98 lines (87 loc) · 2.65 KB
/
Copy pathdir_wrapper.go
File metadata and controls
98 lines (87 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package fs
import (
"context"
"time"
)
// DirWrapper wraps a Directory object so the Remote can be overridden
type DirWrapper struct {
Directory // Directory we are wrapping
remote string // name of the directory
failSilently bool // if set, ErrorNotImplemented should not be considered an error for this directory
}
// NewDirWrapper creates a wrapper for a directory object
//
// This passes through optional methods and should be used for
// wrapping backends to wrap native directories.
func NewDirWrapper(remote string, d Directory) *DirWrapper {
return &DirWrapper{
Directory: d,
remote: remote,
}
}
// NewLimitedDirWrapper creates a DirWrapper that should fail silently instead of erroring for ErrorNotImplemented.
//
// Intended for exceptional dirs lacking abilities that the Fs otherwise usually supports
// (ex. a Combine root which can't set metadata/modtime, regardless of support by wrapped backend)
func NewLimitedDirWrapper(remote string, d Directory) *DirWrapper {
dw := NewDirWrapper(remote, d)
dw.failSilently = true
return dw
}
// String returns the name
func (d *DirWrapper) String() string {
return d.remote
}
// Remote returns the remote path
func (d *DirWrapper) Remote() string {
return d.remote
}
// SetRemote sets the remote
func (d *DirWrapper) SetRemote(remote string) *DirWrapper {
d.remote = remote
return d
}
// Metadata returns metadata for an DirEntry
//
// It should return nil if there is no Metadata
func (d *DirWrapper) Metadata(ctx context.Context) (Metadata, error) {
do, ok := d.Directory.(Metadataer)
if !ok {
return nil, nil
}
return do.Metadata(ctx)
}
// SetMetadata sets metadata for an DirEntry
//
// It should return fs.ErrorNotImplemented if it can't set metadata
func (d *DirWrapper) SetMetadata(ctx context.Context, metadata Metadata) error {
do, ok := d.Directory.(SetMetadataer)
if !ok {
if d.failSilently {
Debugf(d, "Can't SetMetadata for this directory (%T from %v) -- skipping", d.Directory, d.Fs())
return nil
}
return ErrorNotImplemented
}
return do.SetMetadata(ctx, metadata)
}
// SetModTime sets the metadata on the DirEntry to set the modification date
//
// If there is any other metadata it does not overwrite it.
func (d *DirWrapper) SetModTime(ctx context.Context, t time.Time) error {
do, ok := d.Directory.(SetModTimer)
if !ok {
if d.failSilently {
Debugf(d, "Can't SetModTime for this directory (%T from %v) -- skipping", d.Directory, d.Fs())
return nil
}
return ErrorNotImplemented
}
return do.SetModTime(ctx, t)
}
// Check interfaces
var (
_ DirEntry = (*DirWrapper)(nil)
_ Directory = (*DirWrapper)(nil)
_ FullDirectory = (*DirWrapper)(nil)
)