mirror of
https://github.com/rclone/rclone.git
synced 2024-12-22 15:11:56 +01:00
serve webdav: fix incorrect Content-Type immediately after upload
Before this change, if the Content-Type for an object was read immediately after upload (before the object had been uploaded to the backing store) then the Content-Type would be returned incorrectly. This error would be more likely with `--vfs-cache-mode full` and `writes` but may have been possible with the other `--vfs-cache-mode`s. This fixes the problem by always returning a sensible guess at the content type - the same guess we would use for uploading the object. Fixes #6433
This commit is contained in:
parent
be53dcc9c9
commit
f4d822626e
@ -377,18 +377,21 @@ func (fi FileInfo) ETag(ctx context.Context) (etag string, err error) {
|
||||
// ContentType returns a content type for the FileInfo
|
||||
func (fi FileInfo) ContentType(ctx context.Context) (contentType string, err error) {
|
||||
// defer log.Trace(fi, "")("etag=%q, err=%v", &contentType, &err)
|
||||
node, ok := (fi.FileInfo).(vfs.Node)
|
||||
if !ok {
|
||||
fs.Errorf(fi, "Expecting vfs.Node, got %T", fi.FileInfo)
|
||||
return "application/octet-stream", nil
|
||||
}
|
||||
entry := node.DirEntry()
|
||||
switch x := entry.(type) {
|
||||
case fs.Object:
|
||||
return fs.MimeType(ctx, x), nil
|
||||
case fs.Directory:
|
||||
if fi.IsDir() {
|
||||
return "inode/directory", nil
|
||||
}
|
||||
fs.Errorf(fi, "Expecting fs.Object or fs.Directory, got %T", entry)
|
||||
return "application/octet-stream", nil
|
||||
if node, ok := (fi.FileInfo).(vfs.Node); !ok {
|
||||
fs.Errorf(fi, "Expecting vfs.Node, got %T", fi.FileInfo)
|
||||
} else {
|
||||
entry := node.DirEntry()
|
||||
switch x := entry.(type) {
|
||||
case nil:
|
||||
// object hasn't been uploaded yet if entry is nil
|
||||
case fs.Object:
|
||||
return fs.MimeType(ctx, x), nil
|
||||
default:
|
||||
fs.Errorf(fi, "Expecting fs.Object or nil, got %T", entry)
|
||||
}
|
||||
}
|
||||
return fs.MimeTypeFromName(fi.Name()), nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user