Skip to content

Instantly share code, notes, and snippets.

@cygx

cygx/append.diff Secret

Created April 13, 2017 20:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cygx/795dc8f57e0f5e2606072c3cca650574 to your computer and use it in GitHub Desktop.
Save cygx/795dc8f57e0f5e2606072c3cca650574 to your computer and use it in GitHub Desktop.
diff --git a/src/vm/jvm/runtime/org/perl6/nqp/io/FileHandle.java b/src/vm/jvm/runtime/org/perl6/nqp/io/FileHandle.java
index 7921efa..a3577d1 100644
--- a/src/vm/jvm/runtime/org/perl6/nqp/io/FileHandle.java
+++ b/src/vm/jvm/runtime/org/perl6/nqp/io/FileHandle.java
@@ -20,8 +20,9 @@ public class FileHandle extends SyncHandle implements IIOSeekable, IIOLockable {
FileChannel fc;
FileLock lock;
protected boolean eof = false;
+ protected boolean append = false;
- public static OpenOption[] resolveOpenMode(String mode) {
+ protected OpenOption[] resolveOpenMode(String mode) {
if(mode.length() == 0)
return null;
@@ -45,7 +46,7 @@ public class FileHandle extends SyncHandle implements IIOSeekable, IIOLockable {
}
while (pos < mode.length()) switch (mode.charAt(pos++)) {
- case 'a': opts.add(StandardOpenOption.APPEND); break;
+ case 'a': append = true; break;
case 'c': opts.add(StandardOpenOption.CREATE); break;
case 't': opts.add(StandardOpenOption.TRUNCATE_EXISTING); break;
case 'x': opts.add(StandardOpenOption.CREATE_NEW); break;
@@ -162,4 +163,14 @@ public class FileHandle extends SyncHandle implements IIOSeekable, IIOLockable {
}
}
}
+
+ protected long write(ThreadContext tc, ByteBuffer buffer) {
+ if(append) try {
+ fc.position(fc.size());
+ }
+ catch (IOException e) {
+ throw ExceptionHandling.dieInternal(tc, e);
+ }
+ return super.write(tc, buffer);
+ }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment