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 dlna: sort the directory entries by directories first then alphabetically by name

Nick Craig-Wood45b76908677a
diff --git a/cmd/serve/dlna/cds.go b/cmd/serve/dlna/cds.go
index 2e2752c73..adcc580df 100644
--- a/cmd/serve/dlna/cds.go
+++ b/cmd/serve/dlna/cds.go
@@ -11,6 +11,7 @@ import (
"path"
"path/filepath"
"regexp"
+ "sort"
"strings"
"github.com/anacrolix/dms/dlna"
@@ -158,6 +159,18 @@ func (cds *contentDirectoryService) readContainer(o object, host string) (ret []
}
}
+ // Sort the directory entries by directories first then alphabetically by name
+ sort.Slice(dirEntries, func(i, j int) bool {
+ iNode, jNode := dirEntries[i], dirEntries[j]
+ iIsDir, jIsDir := iNode.IsDir(), jNode.IsDir()
+ if iIsDir && !jIsDir {
+ return true
+ } else if !iIsDir && jIsDir {
+ return false
+ }
+ return strings.ToLower(iNode.Name()) < strings.ToLower(jNode.Name())
+ })
+
dirEntries, mediaResources := mediaWithResources(dirEntries)
for _, de := range dirEntries {
child := object{