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

serve webdav: fix error: Expecting fs.Object or fs.Directory, got <nil>

Nick Craig-Wood29b1751d0eb9
diff --git a/cmd/serve/webdav/webdav.go b/cmd/serve/webdav/webdav.go
index 0af46ec4d..ae8c4f2d1 100644
--- a/cmd/serve/webdav/webdav.go
+++ b/cmd/serve/webdav/webdav.go
@@ -6,8 +6,10 @@ import (
"encoding/xml"
"errors"
"fmt"
+ "mime"
"net/http"
"os"
+ "path"
"strconv"
"strings"
"time"
@@ -580,12 +582,14 @@ func (fi FileInfo) ContentType(ctx context.Context) (contentType string, err err
fs.Errorf(fi, "Expecting vfs.Node, got %T", fi.FileInfo)
return "application/octet-stream", nil
}
- entry := node.DirEntry()
+ entry := node.DirEntry() // can be nil
switch x := entry.(type) {
case fs.Object:
return fs.MimeType(ctx, x), nil
case fs.Directory:
return "inode/directory", nil
+ case nil:
+ return mime.TypeByExtension(path.Ext(node.Name())), nil
}
fs.Errorf(fi, "Expecting fs.Object or fs.Directory, got %T", entry)
return "application/octet-stream", nil