Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

lsf: Add 'm' format specifier to show the MimeType

Nick Craig-Woodf77efc7649e8
diff --git a/cmd/lsf/lsf.go b/cmd/lsf/lsf.go
index d05b277be..0a7468286 100644
--- a/cmd/lsf/lsf.go
+++ b/cmd/lsf/lsf.go
@@ -64,6 +64,7 @@ output:
t - modification time
h - hash
i - ID of object if known
+ m - MimeType of object if known
So if you wanted the path, size and modification time, you would use
--format "pst", or maybe --format "tsp" to put the path last.
@@ -141,6 +142,8 @@ func Lsf(fsrc fs.Fs, out io.Writer) error {
list.AddHash(hashType)
case 'i':
list.AddID()
+ case 'm':
+ list.AddMimeType()
default:
return errors.Errorf("Unknown format character %q", char)
}
diff --git a/fs/operations/operations.go b/fs/operations/operations.go
index c0998b696..f4da97366 100644
--- a/fs/operations/operations.go
+++ b/fs/operations/operations.go
@@ -1430,6 +1430,13 @@ func (l *ListFormat) AddID() {
})
}
+// AddMimeType adds file's MimeType to the output if known
+func (l *ListFormat) AddMimeType() {
+ l.AppendOutput(func() string {
+ return fs.MimeTypeDirEntry(l.entry)
+ })
+}
+
// AppendOutput adds string generated by specific function to printed output
func (l *ListFormat) AppendOutput(functionToAppend func() string) {
if len(l.output) > 0 {
diff --git a/fs/operations/operations_test.go b/fs/operations/operations_test.go
index a0cedbc43..a8abc918f 100644
--- a/fs/operations/operations_test.go
+++ b/fs/operations/operations_test.go
@@ -716,6 +716,11 @@ func TestListFormat(t *testing.T) {
list.AddID()
_ = operations.ListFormatted(&items[0], &list) // Can't really check anything - at least it didn't panic!
+ list.SetOutput(nil)
+ list.AddMimeType()
+ assert.Contains(t, operations.ListFormatted(&items[0], &list), "/")
+ assert.Equal(t, "inode/directory", operations.ListFormatted(&items[1], &list))
+
list.SetOutput(nil)
list.AddSize()
assert.Equal(t, "1", operations.ListFormatted(&items[0], &list))