google / google/jimfs

Allow mutable File Size attribute and/or overriding Attribute providers

Open
#38 1 comment 2 reactions 0 assignees View on GitHub
P4 type=enhancement
Dominant language
Java
Stars
2.6k
Forks
296
Avg merge
9m
Merged PRs (30d)
7

Description

Hey guys,

I'm looking to use JimFS to test some logic around a File system visitor I've written thats very sensitive to both the timestamp that a file is modified (✓ -- [BasicAttributeProvider supports `setLastModifiedTime`](https://github.com/google/jimfs/blob/fdc12fe9e0edb4cb952a371df1f43e67d2f8f459/jimfs/src/main/java/com/google/common/jimfs/BasicAttributeProvider.java#L96)) and how large that file is (✗ -- [BasicAttributeProvider throws `unsettable` for any attemps to set the size](https://github.com/google/jimfs/blob/fdc12fe9e0edb4cb952a371df1f43e67d2f8f459/jimfs/src/main/java/com/google/common/jimfs/BasicAttributeProvider.java#L108)).

There are a couple of workarounds I can currently employ:
- our domain logic involves looking at files that are many megabytes big --making creation of these files in an in-memory file system distasteful, but I can probably inject these size & threshold values into our service components to have our logic trigger on much smaller files, and then simply create files on the order of a few kilobytes in memory.
- I can wrap all of our length testing operations in an interface and simply have that interface supply me with the `setLength` operation I need in a testing environment. This has a little bit of a tricky life cycle requirement --I need to make sure the right objects get the right instances, but it would do the job.

That said, support from JimFS for setting the size attribute would allow me to write code that is a step closer to what is actually running in deployment.

Any chance you guys would consider making the file size settable? I understand that this leads to a number of logical inconsistencies (the most obvious: what do we do if we open a stream to a file whose length was programmatically set?)

One solution might be to allow users to write custom `AttributeProvider` objects and register them with JimFS. This would require exposing the `File` instances you guys keep to programmers, and would require that JimFS use some kind of hierarchical search scheme when looking up which Attribute provider to use, but would allow for a great deal of flexibility.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.