afero
afero copied to clipboard
MemMapFs open windows absolute path does not exist
Doing fs.Open("c:\\")
or afero.Walk
from root on a MemMapFs in a windows system returns the error open c:\: file does not exist
. During debugging, I found that the getData()
function in MemMapFs does not support windows root as shown by the TODO in it (https://github.com/spf13/afero/blob/master/memmap.go#L38).
I would like to fix it in my fork, if it is okay.
In my head, MemMapFs
is another filesystem ... And I don't see how that could/should emulate different file systems.
fs.Open("c:\\")
when the fs is a map does not make much sense to me, but maybe it does to others ...
I agree, but MemMapFs
is a great testing tool and I think it would be really beneficial for it to be able to emulate different file systems.
I encountered the problem during testing a program I am working on. Part of the code is to process absolute filepaths and it uses these filepaths to generate files. We wanted to test that the files were created in MemMapFs
by walking from the system root. It works on Linux, but it could never work on Windows because c:\\
was never initialized and we have to start from c:\\
because the function filepath.Abs
from the package path/filepaths
would attach volume names in Windows.
I don't think the changes I made in #226 would change how MemMapFs
works, it can still be another filesystem, it's just going to be more compatible with path/filepaths
There are uses for both, a generic memory-mapped file system, as well as a memory-mapped OS mock file system. We need file systems like MemMapFsWindows
, MemMapFsLinux
and a convenience method afero.NewMemMapFsOs()
to get one according to runtime.GOOS
. If I have Windows-specific functionality in my file system-savvy code, I can otherwise not test it with afero
.
I believe what OP (and I) could use is something along the lines of afero.Abs()
, with a working directory parameter if need be.
@nofun97 It has been three years; do you remember if or how you solved the problem?
afero.Abs()
@MMulthaupt do you mean IsAbs
?
same things happen with fs.MkdirAll
because of
https://github.com/spf13/afero/blob/5c4385aa20510dba5ca4db12c02b0c9211d82892/basepath.go#L76-L78