Skip to content

Loading…

File.truncate should not move write pointer #473

Merged
merged 1 commit into from

2 participants

@atambo
JRuby Team member

No description provided.

@BanzaiMan BanzaiMan merged commit 95f2fc5 into jruby:master

1 check passed

Details default The Travis build passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 2, 2013
  1. @atambo
View
1 spec/tags/1.8/ruby/core/file/truncate_tags.txt
@@ -1 +0,0 @@
-fails:File#truncate does not move the file write pointer to the specified byte offset
View
1 spec/tags/1.9/ruby/core/file/truncate_tags.txt
@@ -1 +0,0 @@
-fails:File#truncate does not move the file write pointer to the specified byte offset
View
4 src/org/jruby/util/io/ChannelStream.java
@@ -1122,18 +1122,18 @@ public synchronized void ftruncate(long newLength) throws IOException,
}
invalidateBuffer();
FileChannel fileChannel = (FileChannel)ch;
+ long position = fileChannel.position();
if (newLength > fileChannel.size()) {
// truncate can't lengthen files, so we save position, seek/write, and go back
- long position = fileChannel.position();
int difference = (int)(newLength - fileChannel.size());
fileChannel.position(fileChannel.size());
// FIXME: This worries me a bit, since it could allocate a lot with a large newLength
fileChannel.write(ByteBuffer.allocate(difference));
- fileChannel.position(position);
} else {
fileChannel.truncate(newLength);
}
+ fileChannel.position(position);
}
/**
Something went wrong with that request. Please try again.