File: dir.go

package info (click to toggle)
rclone 1.45-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 24,300 kB
  • sloc: python: 364; sh: 255; makefile: 190; xml: 30
file content (97 lines) | stat: -rw-r--r-- 2,048 bytes parent folder | download | duplicates (2)
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
package fs

import "time"

// Dir describes an unspecialized directory for directory/container/bucket lists
type Dir struct {
	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
	id      string    // optional ID
}

// NewDir creates an unspecialized Directory object
func NewDir(remote string, modTime time.Time) *Dir {
	return &Dir{
		remote:  remote,
		modTime: modTime,
		size:    -1,
		items:   -1,
	}
}

// NewDirCopy creates an unspecialized copy of the Directory object passed in
func NewDirCopy(d Directory) *Dir {
	return &Dir{
		remote:  d.Remote(),
		modTime: d.ModTime(),
		size:    d.Size(),
		items:   d.Items(),
	}
}

// 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
}

// 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
}

// 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.modTime.IsZero() {
		return d.modTime
	}
	return time.Now()
}

// 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)
)