Hi Mario,
this looks like a good patch so +1 from me. Just to note that we've been
discussing the VMFile interface in a Jikes RVM tracker [1] and that on
IRC MJW pointed out that GCJ's implementation appeared to vary from that
of Classpath [2] [3] [4].
Regards,
Ian
[1] http://jira.codehaus.org/browse/RVM-427
[2] http://gcc.gnu.org/viewcvs/*checkout*/trunk/libjava/java/io/File.java
[3]
http://gcc.gnu.org/viewcvs/*checkout*/trunk/libjava/java/io/natFileWin32.cc
[4]
http://gcc.gnu.org/viewcvs/*checkout*/trunk/libjava/java/io/natFilePosix.cc
Mario Torre wrote:
Hello all!
I would like to submit this fix.
The problem is that to detect if a file is writable we actually open it
for writing... Even worse, in the case of a directory, we write to it a
temp file!
There are a number of issues that I see wrong here, but what worries me
most is that these operations can kill filesystem that reside on compact
flash memories and other devices that have a limited number of write.
The current fix does two things.
1. introduce a new method, native, canWriteDirectory(String path)
This method is meant to be implemented by whoever implements the VM
interface, so that it can do nice things with their target environment.
The default implementation works on Linux and should work on any *nix
operating systems. I've left canWriteDirectory(File file) for backward
compatibility, but I guess no one uses this anyway (it defer to the
native method).
2. Change the implementation of Java_java_io_VMFile_canWrite and
Java_java_io_VMFile_canRead so that they use cpio_checkAccess now,
instead of doing the old "The lazy man's way out" (which is also more
code, btw...)
I'm going to submit this today if no one complains, any ideas?
Ah, before I forget, there are a number of unrelated fixes like
indentation and all the function signature now reflect the fact that
these methods are static (jclass instead of jobject). It would be handy
here to use mercurial (hg record) to separate patchsets.
Mario
2008-04-09 Mario Torre <[EMAIL PROTECTED]>
* java/io/File.java (canWrite): use canWriteDirectory(String).
* vm/reference/java/io/VMFile.java (canWriteDirectory): new native
method.
* native/jni/java-io/java_io_VMFile.c: correct indentation, sync
function
names with header file definition.
(Java_java_io_VMFile_canRead): use cpio_checkAccess to get access
permission. Removed unused variable.
(Java_java_io_VMFile_canWrite): likewise.
(Java_java_io_VMFile_canWriteDirectory): new function.