1
0
mirror of https://github.com/nxshock/gallery.git synced 2024-11-27 00:11:00 +05:00

Fix issues with Windows paths

This commit is contained in:
nxshock 2023-04-10 19:56:46 +05:00
parent 41d00de7b7
commit a0300680bb
2 changed files with 13 additions and 2 deletions

View File

@ -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
}

View File

@ -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)