afero icon indicating copy to clipboard operation
afero copied to clipboard

MemMapFs open windows absolute path does not exist

Open nofun97 opened this issue 5 years ago • 5 comments

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.

nofun97 avatar Nov 10 '19 23:11 nofun97

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 ...

bep avatar Jan 15 '20 09:01 bep

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

nofun97 avatar Jan 15 '20 10:01 nofun97

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.

MMulthaupt avatar Jan 02 '23 23:01 MMulthaupt

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?

MMulthaupt avatar Jan 02 '23 23:01 MMulthaupt

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

Monirzadeh avatar Jan 27 '24 17:01 Monirzadeh