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: fix invalid dc:date for containers

Nick Craig-Wood6d0bca0fc899
diff --git a/cmd/serve/dlna/cds.go b/cmd/serve/dlna/cds.go
index 81e3e05f7..1b9468404 100644
--- a/cmd/serve/dlna/cds.go
+++ b/cmd/serve/dlna/cds.go
@@ -44,6 +44,7 @@ func (cds *contentDirectoryService) cdsObjectToUpnpavObject(cdsObject object, fi
if fileInfo.IsDir() {
obj.Class = "object.container.storageFolder"
obj.Title = fileInfo.Name()
+ obj.Date = upnpav.Timestamp{Time: fileInfo.ModTime()}
childCount, err := cds.countChildren(cdsObject.Path)
if err != nil {
fs.Debugf(cds, "error counting children of %s: %v", cdsObject.Path, err)
diff --git a/cmd/serve/dlna/upnpav/upnpav.go b/cmd/serve/dlna/upnpav/upnpav.go
index c6dc9dc4f..10fa70c37 100644
--- a/cmd/serve/dlna/upnpav/upnpav.go
+++ b/cmd/serve/dlna/upnpav/upnpav.go
@@ -58,7 +58,11 @@ type Timestamp struct {
time.Time
}
-// MarshalXML formats the Timestamp per DIDL-Lite spec
+// MarshalXML formats the Timestamp per DIDL-Lite spec.
+// Zero times are omitted to avoid producing invalid dates like "0001-01-01".
func (t Timestamp) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
+ if t.IsZero() {
+ return nil
+ }
return e.EncodeElement(t.Format("2006-01-02"), start)
}