|
Error occurs on trunk as well: The problem was caused by the file_name passed to truncate being an absolute path. The JRuby truncate method used public File(String parent, String child), which appended the file_name to the current working directory. This results in the following: runtime> current_directory = /home/btatnall/working/jruby/trunk/jruby arg1> filename = /var/run/gem_server.pid testfile> name = gem_server.pid testfile> parent = /home/btatnall/working/jruby/trunk/jruby/var/run testfile> path = /home/btatnall/working/jruby/trunk/jruby/var/run/gem_server.pid testfile> exists = false Notice that parent path is the current working directory combined with the dirname of the filename passed in. Here's a patch that works on my system. I'm having a hard time getting the proper tests to run. btatnall@btatnall00:~/working/jruby/trunk/jruby$ svn diff
Index: src/org/jruby/RubyFile.java
===================================================================
--- src/org/jruby/RubyFile.java (revision 7803)
+++ src/org/jruby/RubyFile.java (working copy)
@@ -1432,8 +1432,17 @@
Ruby runtime = context.getRuntime();
RubyString filename = arg1.convertToString(); // TODO: SafeStringValue here
RubyInteger newLength = arg2.convertToInteger();
-
- if (!new File(runtime.getCurrentDirectory(), filename.getByteList().toString()).exists()) {
+
+ File testFile ;
+ File childFile = new File(filename.getByteList().toString() );
+
+ if ( childFile.isAbsolute() ) {
+ testFile = childFile ;
+ } else {
+ testFile = new File(runtime.getCurrentDirectory(), filename.getByteList().toString());
+ }
+
+ if (!testFile.exists()) {
throw runtime.newErrnoENOENTError(
"No such file or directory - " + filename.getByteList().toString());
}
@@ -1441,7 +1450,7 @@
if (newLength.getLongValue() < 0) {
throw runtime.newErrnoEINVALError("invalid argument: " + filename);
}
-
+
IRubyObject[] args = new IRubyObject[] { filename, runtime.newString("r+") };
RubyFile file = (RubyFile) open(context, recv, args, Block.NULL_BLOCK);
file.truncate(context, newLength);
I've added a spec to the RubySpecs project here: Good find, marking for 1.1.5. Testing now. Tests appear to run ok, so I went ahead with it. Thanks for the patch and rubyspecs update! |
|||||||||||||||||||||||||||||||||||||||||
Should be File::truncate instead of File#truncate.