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

lsjson: add --no-mimetype flag, speed up lsf

Nick Craig-Woodbfd9f32188f2
diff --git a/cmd/lsf/lsf.go b/cmd/lsf/lsf.go
index bd46734df..f82972e6b 100644
--- a/cmd/lsf/lsf.go
+++ b/cmd/lsf/lsf.go
@@ -166,10 +166,11 @@ func Lsf(ctx context.Context, fsrc fs.Fs, out io.Writer) error {
list.SetDirSlash(dirSlash)
list.SetAbsolute(absolute)
var opt = operations.ListJSONOpt{
- NoModTime: true,
- DirsOnly: dirsOnly,
- FilesOnly: filesOnly,
- Recurse: recurse,
+ NoModTime: true,
+ NoMimeType: true,
+ DirsOnly: dirsOnly,
+ FilesOnly: filesOnly,
+ Recurse: recurse,
}
for _, char := range format {
@@ -188,6 +189,7 @@ func Lsf(ctx context.Context, fsrc fs.Fs, out io.Writer) error {
list.AddID()
case 'm':
list.AddMimeType()
+ opt.NoMimeType = false
case 'e':
list.AddEncrypted()
opt.ShowEncrypted = true
diff --git a/cmd/lsjson/lsjson.go b/cmd/lsjson/lsjson.go
index aecdc2e99..ba79fd282 100644
--- a/cmd/lsjson/lsjson.go
+++ b/cmd/lsjson/lsjson.go
@@ -24,6 +24,7 @@ func init() {
flags.BoolVarP(cmdFlags, &opt.Recurse, "recursive", "R", false, "Recurse into the listing.")
flags.BoolVarP(cmdFlags, &opt.ShowHash, "hash", "", false, "Include hashes in the output (may take longer).")
flags.BoolVarP(cmdFlags, &opt.NoModTime, "no-modtime", "", false, "Don't read the modification time (can speed things up).")
+ flags.BoolVarP(cmdFlags, &opt.NoMimeType, "no-mimetype", "", false, "Don't read the mime type (can speed things up).")
flags.BoolVarP(cmdFlags, &opt.ShowEncrypted, "encrypted", "M", false, "Show the encrypted names.")
flags.BoolVarP(cmdFlags, &opt.ShowOrigIDs, "original", "", false, "Show the ID of the underlying Object.")
flags.BoolVarP(cmdFlags, &opt.FilesOnly, "files-only", "", false, "Show only files in the listing.")
@@ -59,7 +60,9 @@ The output is an array of Items, where each Item looks like this
If --hash is not specified the Hashes property won't be emitted.
-If --no-modtime is specified then ModTime will be blank.
+If --no-modtime is specified then ModTime will be blank. This can speed things up on remotes where reading the ModTime takes an extra request (eg s3, swift).
+
+If --no-mimetype is specified then MimeType will be blank. This can speed things up on remotes where reading the MimeType takes an extra request (eg s3, swift).
If --encrypted is not specified the Encrypted won't be emitted.
diff --git a/fs/operations/lsjson.go b/fs/operations/lsjson.go
index f49e72816..f8a9e28bd 100644
--- a/fs/operations/lsjson.go
+++ b/fs/operations/lsjson.go
@@ -71,6 +71,7 @@ func formatForPrecision(precision time.Duration) string {
type ListJSONOpt struct {
Recurse bool `json:"recurse"`
NoModTime bool `json:"noModTime"`
+ NoMimeType bool `json:"noMimeType"`
ShowEncrypted bool `json:"showEncrypted"`
ShowOrigIDs bool `json:"showOrigIDs"`
ShowHash bool `json:"showHash"`
@@ -114,14 +115,16 @@ func ListJSON(ctx context.Context, fsrc fs.Fs, remote string, opt *ListJSONOpt,
}
item := ListJSONItem{
- Path: entry.Remote(),
- Name: path.Base(entry.Remote()),
- Size: entry.Size(),
- MimeType: fs.MimeTypeDirEntry(ctx, entry),
+ Path: entry.Remote(),
+ Name: path.Base(entry.Remote()),
+ Size: entry.Size(),
}
if !opt.NoModTime {
item.ModTime = Timestamp{When: entry.ModTime(ctx), Format: format}
}
+ if !opt.NoMimeType {
+ item.MimeType = fs.MimeTypeDirEntry(ctx, entry)
+ }
if cipher != nil {
switch entry.(type) {
case fs.Directory: