mirror of
https://github.com/rclone/rclone.git
synced 2026-05-12 10:03:35 -04:00
serve dlna: fix container childCount to reflect actual contents
The childCount attribute on DLNA containers was hardcoded to 1 regardless of how many items the directory actually contained. Some DLNA clients (notably Samsung TVs) use childCount to decide whether to browse into a container. Report the actual number of directory entries instead. See #9346
This commit is contained in:
@@ -42,12 +42,16 @@ func (cds *contentDirectoryService) cdsObjectToUpnpavObject(cdsObject object, fi
|
||||
}
|
||||
|
||||
if fileInfo.IsDir() {
|
||||
defaultChildCount := 1
|
||||
obj.Class = "object.container.storageFolder"
|
||||
obj.Title = fileInfo.Name()
|
||||
childCount, err := cds.countChildren(cdsObject.Path)
|
||||
if err != nil {
|
||||
fs.Debugf(cds, "error counting children of %s: %v", cdsObject.Path, err)
|
||||
childCount = 0
|
||||
}
|
||||
return upnpav.Container{
|
||||
Object: obj,
|
||||
ChildCount: &defaultChildCount,
|
||||
ChildCount: &childCount,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -266,6 +270,23 @@ func (cds *contentDirectoryService) objectFromID(id string) (o object, err error
|
||||
return
|
||||
}
|
||||
|
||||
// countChildren returns the number of child items in a directory.
|
||||
func (cds *contentDirectoryService) countChildren(dirPath string) (int, error) {
|
||||
node, err := cds.vfs.Stat(dirPath)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
dir, ok := node.(*vfs.Dir)
|
||||
if !ok {
|
||||
return 0, nil
|
||||
}
|
||||
entries, err := dir.ReadDirAll()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return len(entries), nil
|
||||
}
|
||||
|
||||
func (cds *contentDirectoryService) Handle(action string, argsXML []byte, r *http.Request) ([]soapArg, error) {
|
||||
host := r.Host
|
||||
|
||||
|
||||
Reference in New Issue
Block a user