Repository navigation
Conversation
eppleton
left a comment
There was a problem hiding this comment.
Making toPath work for every FileObject sounds useful, and the shared PathTestHid suite is a good base. Some observations from reading the code and checking the JDK and bootstrap sources; I didn't build or run the PR.
Most of the points below share one root: every PathTestHid test derives all paths from a single toPath() call, and on the fallback (non-disk) side the suite currently only runs on JarFileSystem, which is read-only. So equality across separate toPath() calls, writable virtual filesystems (MemoryFileSystem, MultiFileSystem/layers) and watch events are not exercised yet. Your "other filesystems" checklist item would catch several of these.
On the API side: toPath on master is only used from tests, so the new "never null" contract shouldn't break anything in the repo, but platform applications may use null as "not on disk". An apichanges.xml entry and a spec version bump would make that visible (I see it's on your checklist).
FileUtil.toPath to never return null
| */ | ||
| public static Path toPath(FileObject fo) { | ||
| Parameters.notNull("fo", fo); | ||
| File f = toFile(fo); |
There was a problem hiding this comment.
Maybe check for (Path) fo.getAttribute("java.nio.Path") first, and make trivial change to masterfs to return directly? Could allow for better optimization from file system implementations in future and/or option to switch in nio2 based memory and zip filesystems.
Is conversion via attribute documented?
There was a problem hiding this comment.
toFile(fo)check was put here by @lkishalmi and I am trying to not modify it.- it works fine for
LocalFileSystemand masterfs to provide the underlayingPathimplementations - it works less well for
MultiFileSystemwhich can also have underlaying impl- there I will have to disable the delegation
- but that can be done locally inside the module now ...
- ... without any visible API
Is conversion via attribute documented?
- probably it is not
- it should be listed in this table
check for (Path) fo.getAttribute("java.nio.Path")
- not in this PR (unless necessary), but for the future I'd like to do something bigger:
- let us add
FileObject implements Path! - then any
FileObjectwill immediately be usable with any JDK path oriented API
There was a problem hiding this comment.
it should be listed in this table
Yes, I checked there before commenting. Would have thought there and/or in the Javadoc for the method?
...for the future I'd like to do something bigger:
let us addFileObject implements Path!
Every FileObject having a Path sounds great. Every FileObject being a Path might not be so good an idea. Paths from the same provider are special cased (eg. in Files::copy and the providers expect to be able to cast to implementation (eg. UnixPath). That means that a FileObject from masterfs would bypass the optimal same-provider pathways.
|
Thanks! Good changes in the right direction. We need to look at replacing uses of |
eppleton
left a comment
There was a problem hiding this comment.
Thanks for the new tests and the fixes to relative paths. getRoot/getParent returning null for relative paths, normalize keeping leading .., and resolve(String) honouring absolute arguments all match the Path contract now. The WatchService close handling also looks right to me: the close marker is passed on so every blocked take() wakes up.
A few notes on the new FileChannel emulation, from reading the code (I haven't run it); details inline. One earlier point is still open: toUri() still calls fileObject.toURI() without a null check (see my reply in the thread on NioPathForFileObject).
078b1cd to
dc6a31a
Compare
|
There are failures in masters tests on four platforms: [junit] Deleting the watched directory must signal its key expected same:sun.nio.fs.LinuxWatchService$LinuxWatchKey@5d00411a was not: |
|
toUri() still calls fileObject.toURI() without a null check |
|
Thanks for the rework. I re-read the channel code at 61f31e8:
Two points from earlier are still open:
|
Done in 674cb63
Amazing catch. I wrote an always enabled action, did the check there and yes, the I consider this done, I am hoping for the approval, @eppleton & co. The plan is to squash and integrated ~Dec 1. |
ba61f03 to
6626bc2
Compare
| if (file != null && file.isValid() && write && options.contains(StandardOpenOption.CREATE_NEW)) { | ||
| throw new FileAlreadyExistsException(path.toString()); | ||
| } | ||
| if (file == null || !file.isValid()) { |
There was a problem hiding this comment.
Note: the specification for StandardOpenOptions.CREATE says:
The check for the existence of the file and the creation of the file if it does not exist is atomic with respect to other file system operations.
Here the existence check is file == null || !file.isValid() - but eventual createData happens non-atomically. So another thread may eventually create the file in between.
There was a problem hiding this comment.
How do you suggest to do it? We are calling into unknown implementation of the filesystem and the filesystem API doesn't seem to have this kind f atomic guarantees...
| this.nioLock = fileLock == null ? null : new NioLock(this, fileLock); | ||
| this.readable = readable; | ||
| this.append = append; | ||
| ByteBuffer content = ByteBuffer.wrap(file.asBytes()); |
There was a problem hiding this comment.
Nitpick: I don't like much sucking entire file content to a byte[] here. Very long files cannot be really accessed through j.n.Files.newByteChannel (even to read a header/preamble !).
But it is documented.
There was a problem hiding this comment.
- there is not much to do about it given the current filesystem API
- but I can imagine we could add
interface AbstractFileSystem.Channel- to allow the filesystem to handle this more effectively (via RandomAccess, or co.)
- but that's for future improvements, not for this PR
|
FileUtil.toPathLocalFileSystemFileObjectnullLocalFileSystemTestand make it pass - done in 1e50301Path<->FileObjectinteractionsI was using VSCode NetBeans extension and VSCode Copilot (Luna model) when coding this change request.