google/jimfs

Empty filesystem contains a "work" dir (that shouldn't be there)

proofrock opened this issue · 6 comments

Hi,
first of all, thanks for this library. I'm trying to use it, but the following code (in Kotlin)...

val fs = Jimfs.newFileSystem(Configuration.unix())
val rootDir = fs.getPath("/")
Files.newDirectoryStream(rootDir).forEach { println(it) }

...prints...

/work

Am I doing something wrong? As far as I can understand, that dir shouldn't be there.

Thanks again for your work!

I see in the code that is created in Configuration.unix() as the working directory. Now my question is: what is a working directory, and can I delete it and have a "clean", empty fs?

In the end, I created the fs like this:

Jimfs.newFileSystem(
Configuration.builder(PathType.unix())
.setRoots("/")
.setWorkingDirectory("/")
.setAttributeViews("basic")
.setSupportedFeatures(Feature.SECURE_DIRECTORY_STREAM, Feature.FILE_CHANNEL)
.build())

To get a working directory in the root directory. Still don't know what a working directory is... ;-)

The working directory is the directory that relative paths are resolved against. For the default file system, this is something that's set based on how the JVM is launched.

I agree that the default of /work for the working directory for Jimfs is weird. I didn't, though, want to make / the working directory by default because it would be pretty unusual in a real file system to have the root as your working directory. It may be that it wouldn't be a problem in practice and I was just being paranoid, though. My other thought was that most use cases for Jimfs wouldn't care about whether or not the directory existed, nor what exactly the working directory path was.

seanf commented

Hi @cgdecker

Is @proofrock's code above still the best way to create an empty file system?

onetom commented

We were trying to use Jimfs to test code, which writes into S3 in production via the https://github.com/awslabs/aws-java-nio-spi-for-s3 file system service provider.

In that use case, having / as the current directory would make more sense too.