1
mirror of https://github.com/rclone/rclone synced 2024-12-18 07:45:55 +01:00

lsjson, lsf: support showing the Tier of the object

This commit is contained in:
Nick Craig-Wood 2019-03-20 12:45:06 +00:00
parent eeab7a0a43
commit a57756a05c
3 changed files with 17 additions and 0 deletions

View File

@ -70,6 +70,7 @@ output:
o - Original ID of underlying object
m - MimeType of object if known
e - encrypted name
T - tier of storage if known, eg "Hot" or "Cool"
So if you wanted the path, size and modification time, you would use
--format "pst", or maybe --format "tsp" to put the path last.
@ -191,6 +192,8 @@ func Lsf(fsrc fs.Fs, out io.Writer) error {
case 'o':
list.AddOrigID()
opt.ShowOrigIDs = true
case 'T':
list.AddTier()
default:
return errors.Errorf("Unknown format character %q", char)
}

View File

@ -23,6 +23,7 @@ type ListJSONItem struct {
Hashes map[string]string `json:",omitempty"`
ID string `json:",omitempty"`
OrigID string `json:",omitempty"`
Tier string `json:",omitempty"`
}
// Timestamp a time in the provided format
@ -91,6 +92,7 @@ func ListJSON(fsrc fs.Fs, remote string, opt *ListJSONOpt, callback func(*ListJS
return errors.Wrap(err, "ListJSON failed to make new crypt remote")
}
}
canGetTier := fsrc.Features().GetTier
format := formatForPrecision(fsrc.Precision())
err := walk.ListR(fsrc, remote, false, ConfigMaxDepth(opt.Recurse), walk.ListAll, func(entries fs.DirEntries) (err error) {
for _, entry := range entries {
@ -163,6 +165,11 @@ func ListJSON(fsrc fs.Fs, remote string, opt *ListJSONOpt, callback func(*ListJS
}
}
}
if canGetTier {
if do, ok := x.(fs.GetTierer); ok {
item.Tier = do.GetTier()
}
}
default:
fs.Errorf(nil, "Unknown type %T in listing in ListJSON", entry)
}

View File

@ -1596,6 +1596,13 @@ func (l *ListFormat) AddOrigID() {
})
}
// AddTier adds file's Tier to the output if known
func (l *ListFormat) AddTier() {
l.AppendOutput(func(entry *ListJSONItem) string {
return entry.Tier
})
}
// AddMimeType adds file's MimeType to the output if known
func (l *ListFormat) AddMimeType() {
l.AppendOutput(func(entry *ListJSONItem) string {