2017-06-30 20:37:29 +08:00
|
|
|
package fs
|
|
|
|
|
2019-06-17 16:34:30 +08:00
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"time"
|
|
|
|
)
|
2017-06-30 20:37:29 +08:00
|
|
|
|
|
|
|
// Dir describes an unspecialized directory for directory/container/bucket lists
|
|
|
|
type Dir struct {
|
2024-02-07 23:00:23 +08:00
|
|
|
f Info // Fs this directory is part of
|
2017-06-30 20:37:29 +08:00
|
|
|
remote string // name of the directory
|
|
|
|
modTime time.Time // modification or creation time - IsZero for unknown
|
|
|
|
size int64 // size of directory and contents or -1 if unknown
|
|
|
|
items int64 // number of objects or -1 for unknown
|
2017-08-02 23:44:36 +08:00
|
|
|
id string // optional ID
|
2021-03-12 01:40:29 +08:00
|
|
|
parent string // optional parent directory ID
|
2017-06-30 20:37:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewDir creates an unspecialized Directory object
|
2023-05-03 17:39:42 +08:00
|
|
|
//
|
|
|
|
// If the modTime is unknown pass in time.Time{}
|
2017-06-30 20:37:29 +08:00
|
|
|
func NewDir(remote string, modTime time.Time) *Dir {
|
|
|
|
return &Dir{
|
2024-02-07 23:00:23 +08:00
|
|
|
f: Unknown,
|
2017-06-30 20:37:29 +08:00
|
|
|
remote: remote,
|
|
|
|
modTime: modTime,
|
|
|
|
size: -1,
|
|
|
|
items: -1,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewDirCopy creates an unspecialized copy of the Directory object passed in
|
2019-06-17 16:34:30 +08:00
|
|
|
func NewDirCopy(ctx context.Context, d Directory) *Dir {
|
2017-06-30 20:37:29 +08:00
|
|
|
return &Dir{
|
2024-02-07 23:00:23 +08:00
|
|
|
f: d.Fs(),
|
2017-06-30 20:37:29 +08:00
|
|
|
remote: d.Remote(),
|
2019-06-17 16:34:30 +08:00
|
|
|
modTime: d.ModTime(ctx),
|
2017-06-30 20:37:29 +08:00
|
|
|
size: d.Size(),
|
|
|
|
items: d.Items(),
|
2019-03-20 17:40:04 +08:00
|
|
|
id: d.ID(),
|
2017-06-30 20:37:29 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-07 23:00:23 +08:00
|
|
|
// Fs returns the Fs that this directory is part of
|
|
|
|
func (d *Dir) Fs() Info {
|
|
|
|
return d.f
|
|
|
|
}
|
|
|
|
|
2017-06-30 20:37:29 +08:00
|
|
|
// String returns the name
|
|
|
|
func (d *Dir) String() string {
|
|
|
|
return d.remote
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remote returns the remote path
|
|
|
|
func (d *Dir) Remote() string {
|
|
|
|
return d.remote
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetRemote sets the remote
|
|
|
|
func (d *Dir) SetRemote(remote string) *Dir {
|
|
|
|
d.remote = remote
|
|
|
|
return d
|
|
|
|
}
|
|
|
|
|
2017-08-02 23:44:36 +08:00
|
|
|
// ID gets the optional ID
|
|
|
|
func (d *Dir) ID() string {
|
|
|
|
return d.id
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetID sets the optional ID
|
|
|
|
func (d *Dir) SetID(id string) *Dir {
|
|
|
|
d.id = id
|
|
|
|
return d
|
|
|
|
}
|
|
|
|
|
2021-03-12 01:40:29 +08:00
|
|
|
// ParentID returns the IDs of the Dir parent if known
|
|
|
|
func (d *Dir) ParentID() string {
|
|
|
|
return d.parent
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetParentID sets the optional parent ID of the Dir
|
|
|
|
func (d *Dir) SetParentID(parent string) *Dir {
|
|
|
|
d.parent = parent
|
|
|
|
return d
|
|
|
|
}
|
|
|
|
|
2017-06-30 20:37:29 +08:00
|
|
|
// ModTime returns the modification date of the file
|
2023-05-03 17:39:42 +08:00
|
|
|
//
|
|
|
|
// If one isn't available it returns the configured --default-dir-time
|
2019-06-17 16:34:30 +08:00
|
|
|
func (d *Dir) ModTime(ctx context.Context) time.Time {
|
2017-06-30 20:37:29 +08:00
|
|
|
if !d.modTime.IsZero() {
|
|
|
|
return d.modTime
|
|
|
|
}
|
2023-05-03 17:39:42 +08:00
|
|
|
ci := GetConfig(ctx)
|
|
|
|
return time.Time(ci.DefaultTime)
|
2017-06-30 20:37:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Size returns the size of the file
|
|
|
|
func (d *Dir) Size() int64 {
|
|
|
|
return d.size
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetSize sets the size of the directory
|
|
|
|
func (d *Dir) SetSize(size int64) *Dir {
|
|
|
|
d.size = size
|
|
|
|
return d
|
|
|
|
}
|
|
|
|
|
|
|
|
// Items returns the count of items in this directory or this
|
|
|
|
// directory and subdirectories if known, -1 for unknown
|
|
|
|
func (d *Dir) Items() int64 {
|
|
|
|
return d.items
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetItems sets the number of items in the directory
|
|
|
|
func (d *Dir) SetItems(items int64) *Dir {
|
|
|
|
d.items = items
|
|
|
|
return d
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check interfaces
|
|
|
|
var (
|
|
|
|
_ DirEntry = (*Dir)(nil)
|
|
|
|
_ Directory = (*Dir)(nil)
|
|
|
|
)
|