openAbsolute should strip out the volume name on Windows

This commit is contained in:
Sasha Koshka 2024-03-28 17:16:50 -04:00
parent 4e6103418c
commit 1c61235b63
1 changed files with 8 additions and 1 deletions

View File

@ -108,6 +108,13 @@ func (resolver *Resolver) ResolveCwd (address entity.Address) (string, error) {
// paths, which the FSPL compiler runs on. It converts an absolute path to a
// slash path relative to "/" and opens the file.
func openAbsolute (filesystem fs.FS, path string) (fs.File, error) {
path = strings.TrimPrefix(filepath.ToSlash(path), "/")
rootName := "/"
// FIXME: this does not distinguish between volumes on windows. this is
// a limitation of os.DirFS, we might want our own DirFS implementation
// that has volumes as subdirs of /.
if volumeName := filepath.VolumeName(path); volumeName != "" {
rootName = volumeName
}
path = strings.TrimPrefix(filepath.ToSlash(path), rootName)
return filesystem.Open(path)
}