Fix modtime bug

This commit is contained in:
Mukhtar Akere
2025-07-02 01:17:31 +01:00
parent 2c90e518aa
commit c0aa4eaeba
2 changed files with 4 additions and 7 deletions

View File

@@ -180,7 +180,7 @@ func (h *Handler) getChildren(name string) []os.FileInfo {
if len(parts) == 2 && utils.Contains(h.getParentItems(), parts[0]) {
torrentName := parts[1]
if t := h.cache.GetTorrentByName(torrentName); t != nil {
return h.getFileInfos(t.Torrent)
return h.getFileInfos(t)
}
}
return nil
@@ -267,10 +267,9 @@ func (h *Handler) Stat(ctx context.Context, name string) (os.FileInfo, error) {
return f.Stat()
}
func (h *Handler) getFileInfos(torrent *types.Torrent) []os.FileInfo {
func (h *Handler) getFileInfos(torrent *store.CachedTorrent) []os.FileInfo {
torrentFiles := torrent.GetFiles()
files := make([]os.FileInfo, 0, len(torrentFiles))
now := time.Now()
// Sort by file name since the order is lost when using the map
sortedFiles := make([]*types.File, 0, len(torrentFiles))
@@ -286,7 +285,7 @@ func (h *Handler) getFileInfos(torrent *types.Torrent) []os.FileInfo {
name: file.Name,
size: file.Size,
mode: 0644,
modTime: now,
modTime: torrent.AddedOn,
isDir: false,
})
}

View File

@@ -8,7 +8,6 @@ import (
"path"
"strconv"
"strings"
"time"
)
type contextKey string
@@ -55,7 +54,6 @@ func (h *Handler) handlePropfind(w http.ResponseWriter, r *http.Request) {
rawEntries = append(rawEntries, h.getChildren(cleanPath)...)
}
now := time.Now().UTC().Format("2006-01-02T15:04:05.000-07:00")
entries := make([]entry, 0, len(rawEntries)+1)
// Add the current file itself
entries = append(entries, entry{
@@ -108,7 +106,7 @@ func (h *Handler) handlePropfind(w http.ResponseWriter, r *http.Request) {
}
_, _ = sb.WriteString(`<d:getlastmodified>`)
_, _ = sb.WriteString(now)
_, _ = sb.WriteString(e.modTime)
_, _ = sb.WriteString(`</d:getlastmodified>`)
_, _ = sb.WriteString(`<d:displayname>`)