forked from TrueCloudLab/rclone
Add BasicInfo interface shared between Dir and Object
This commit is contained in:
parent
e27b91ffb8
commit
0805ec051f
1 changed files with 34 additions and 6 deletions
40
fs/fs.go
40
fs/fs.go
|
@ -182,25 +182,31 @@ type Object interface {
|
||||||
|
|
||||||
// ObjectInfo contains information about an object.
|
// ObjectInfo contains information about an object.
|
||||||
type ObjectInfo interface {
|
type ObjectInfo interface {
|
||||||
|
BasicInfo
|
||||||
|
|
||||||
// Fs returns read only access to the Fs that this object is part of
|
// Fs returns read only access to the Fs that this object is part of
|
||||||
Fs() Info
|
Fs() Info
|
||||||
|
|
||||||
// Remote returns the remote path
|
|
||||||
Remote() string
|
|
||||||
|
|
||||||
// Hash returns the selected checksum of the file
|
// Hash returns the selected checksum of the file
|
||||||
// If no checksum is available it returns ""
|
// If no checksum is available it returns ""
|
||||||
Hash(HashType) (string, error)
|
Hash(HashType) (string, error)
|
||||||
|
|
||||||
|
// Storable says whether this object can be stored
|
||||||
|
Storable() bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// BasicInfo common interface for Dir and Object providing the very
|
||||||
|
// basic attributes of an object.
|
||||||
|
type BasicInfo interface {
|
||||||
|
// Remote returns the remote path
|
||||||
|
Remote() string
|
||||||
|
|
||||||
// ModTime returns the modification date of the file
|
// ModTime returns the modification date of the file
|
||||||
// It should return a best guess if one isn't available
|
// It should return a best guess if one isn't available
|
||||||
ModTime() time.Time
|
ModTime() time.Time
|
||||||
|
|
||||||
// Size returns the size of the file
|
// Size returns the size of the file
|
||||||
Size() int64
|
Size() int64
|
||||||
|
|
||||||
// Storable says whether this object can be stored
|
|
||||||
Storable() bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Purger is an optional interfaces for Fs
|
// Purger is an optional interfaces for Fs
|
||||||
|
@ -343,6 +349,28 @@ type Dir struct {
|
||||||
Count int64 // number of objects -1 for unknown
|
Count int64 // number of objects -1 for unknown
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Remote returns the remote path
|
||||||
|
func (d *Dir) Remote() string {
|
||||||
|
return d.Name
|
||||||
|
}
|
||||||
|
|
||||||
|
// ModTime returns the modification date of the file
|
||||||
|
// It should return a best guess if one isn't available
|
||||||
|
func (d *Dir) ModTime() time.Time {
|
||||||
|
if !d.When.IsZero() {
|
||||||
|
return d.When
|
||||||
|
}
|
||||||
|
return time.Now()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Size returns the size of the file
|
||||||
|
func (d *Dir) Size() int64 {
|
||||||
|
return d.Bytes
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check interface
|
||||||
|
var _ BasicInfo = (*Dir)(nil)
|
||||||
|
|
||||||
// DirChan is a channel of Dir objects
|
// DirChan is a channel of Dir objects
|
||||||
type DirChan chan *Dir
|
type DirChan chan *Dir
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue