fixed windows filepath issues by delaying path to filepath conversion (#66)

This commit is contained in:
somesuchnonsense
2025-05-14 12:42:20 -05:00
committed by GitHub
parent 3c8e6bae81
commit 690d7668c1

View File

@@ -75,7 +75,7 @@ func (h *Handler) Rename(ctx context.Context, oldName, newName string) error {
} }
func (h *Handler) getRootPath() string { func (h *Handler) getRootPath() string {
return fmt.Sprintf(filepath.Join(string(os.PathSeparator), "webdav", "%s"), h.Name) return fmt.Sprintf(path.Join("/", "webdav", "%s"), h.Name)
} }
func (h *Handler) getTorrentsFolders(folder string) []os.FileInfo { func (h *Handler) getTorrentsFolders(folder string) []os.FileInfo {
@@ -131,8 +131,8 @@ func (h *Handler) getChildren(name string) []os.FileInfo {
return h.getTorrentsFolders(parent) return h.getTorrentsFolders(parent)
} }
// torrent-folder level (e.g. /root/parentFolder/torrentName) // torrent-folder level (e.g. /root/parentFolder/torrentName)
rel := strings.TrimPrefix(name, root+string(os.PathSeparator)) rel := strings.TrimPrefix(name, root+"/")
parts := strings.Split(rel, string(os.PathSeparator)) parts := strings.Split(rel, "/")
if len(parts) == 2 && utils.Contains(h.getParentItems(), parts[0]) { if len(parts) == 2 && utils.Contains(h.getParentItems(), parts[0]) {
torrentName := parts[1] torrentName := parts[1]
if t := h.cache.GetTorrentByName(torrentName); t != nil { if t := h.cache.GetTorrentByName(torrentName); t != nil {
@@ -152,7 +152,7 @@ func (h *Handler) OpenFile(ctx context.Context, name string, flag int, perm os.F
now := time.Now() now := time.Now()
// 1) special case version.txt // 1) special case version.txt
if name == filepath.Join(rootDir, "version.txt") { if name == path.Join(rootDir, "version.txt") {
versionInfo := version.GetInfo().String() versionInfo := version.GetInfo().String()
return &File{ return &File{
cache: h.cache, cache: h.cache,
@@ -167,7 +167,7 @@ func (h *Handler) OpenFile(ctx context.Context, name string, flag int, perm os.F
// 2) directory case: ask getChildren // 2) directory case: ask getChildren
if children := h.getChildren(name); children != nil { if children := h.getChildren(name); children != nil {
displayName := path.Base(name) displayName := filepath.Clean(path.Base(name))
if name == rootDir { if name == rootDir {
displayName = string(os.PathSeparator) displayName = string(os.PathSeparator)
} }
@@ -184,14 +184,14 @@ func (h *Handler) OpenFile(ctx context.Context, name string, flag int, perm os.F
// 3) filewithintorrent case // 3) filewithintorrent case
// everything else must be a file under a torrent folder // everything else must be a file under a torrent folder
rel := strings.TrimPrefix(name, rootDir+string(os.PathSeparator)) rel := strings.TrimPrefix(name, rootDir+"/")
parts := strings.Split(rel, string(os.PathSeparator)) parts := strings.Split(rel, "/")
if len(parts) >= 2 { if len(parts) >= 2 {
if utils.Contains(h.getParentItems(), parts[0]) { if utils.Contains(h.getParentItems(), parts[0]) {
torrentName := parts[1] torrentName := parts[1]
cached := h.cache.GetTorrentByName(torrentName) cached := h.cache.GetTorrentByName(torrentName)
if cached != nil && len(parts) >= 3 { if cached != nil && len(parts) >= 3 {
filename := filepath.Join(parts[2:]...) filename := filepath.Clean(path.Join(parts[2:]...))
if file, ok := cached.Files[filename]; ok { if file, ok := cached.Files[filename]; ok {
return &File{ return &File{
cache: h.cache, cache: h.cache,