From a0300680bbefaa4d9f29ea2e6e91c52d13d189f4 Mon Sep 17 00:00:00 2001 From: nxshock Date: Mon, 10 Apr 2023 19:56:46 +0500 Subject: [PATCH] Fix issues with Windows paths --- config.go | 8 +++++++- handlers.go | 7 ++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/config.go b/config.go index ad3a2ef..ce1ee59 100644 --- a/config.go +++ b/config.go @@ -20,11 +20,17 @@ func loadConfig(path string) (*Config, error) { return nil, err } + config.WorkingDirectory = filepath.ToSlash(config.WorkingDirectory) + + if len(config.WorkingDirectory) > 0 && string(config.WorkingDirectory[len(config.WorkingDirectory)-1]) != "/" { + config.WorkingDirectory += "/" + } + workingDirectory, err := filepath.Abs(config.WorkingDirectory) if err != nil { return nil, err } - config.WorkingDirectory = workingDirectory + config.WorkingDirectory = filepath.ToSlash(workingDirectory) return &config, nil } diff --git a/handlers.go b/handlers.go index 9d111ad..ae405be 100644 --- a/handlers.go +++ b/handlers.go @@ -15,7 +15,12 @@ func getResponse(path string) ([]Item, error) { } for i := range fileNames { - fileNames[i] = strings.TrimPrefix(filepath.ToSlash(fileNames[i]), filepath.ToSlash(config.WorkingDirectory))[1:] // TODO: check is first slash properly removed + prefix := config.WorkingDirectory + if string(prefix[len(prefix)-1]) == "/" { + prefix = prefix[:len(prefix)-1] + } + + fileNames[i] = strings.TrimPrefix(filepath.ToSlash(fileNames[i]), prefix)[1:] // TODO: check is first slash properly removed } items := make([]Item, 0)