afero
afero copied to clipboard
GetTempDir() not compatible with MemMapFS
I ran into this one while debugging a few tests.
I was under the assumption that the method GetTempDir
would return a valid temporary diretory for use in any FS, as it receives the fs as an argument:
func GetTempDir(fs Fs, subPath string) string
However it seems that in the implementation the os
package is always called:
dir := addSlash(os.TempDir())
Which results in the default temp directory for the system being returned, even when the filesystem in use is MemMapFS.
In my case (MacOS) this results in something like "/var/folders/hb/_83nhz590h95ss_ygd_lpyq00000gn/T/"
being returned, which then fails when you call:
exists, err := afero.Exists(fs, path)
As this directory only exists on the host and not in the memory-backed FS.
My suggestions to fix this are:
- Accept this is the default behavior and document it;
- Return err when this is called on MemMapFS;
- When a new MemMapFS is initialized, also create a default, known temporary directory and return it in the method.
Happy to help implementing any of these.
This should be abstracted to make it possible to add different behaviors based on the kind of storage being used.