Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
proofrock opened this issue Nov 2, 2018 · 6 comments
Open
Labels

Comments

@proofrock
Copy link

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!

@proofrock
Copy link
Author

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?

@proofrock
Copy link
Author

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

@cgdecker
Copy link
Member

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.

@proofrock
Copy link
Author

proofrock commented Mar 24, 2019 via email

@cpovirk cpovirk added the P3 label Jul 25, 2019
@seanf
Copy link

seanf commented Jun 19, 2021

Hi @cgdecker

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

@onetom
Copy link

onetom commented Sep 25, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants