Skip to content

Commit 9a93749

Browse files
committed
Some minor fixes on windows.
1 parent 7d6bb8c commit 9a93749

File tree

3 files changed

+62
-34
lines changed

3 files changed

+62
-34
lines changed

cli/src/main/java/uk/co/bithatch/tnfs/cli/TNFSTP.java

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -487,39 +487,44 @@ public void complete(LineReader reader, ParsedLine line, List<Candidate> candida
487487
private void spawn(String[] args, Object cmd) throws IOException, InterruptedException {
488488
if(args[0].startsWith("!")) {
489489
args[0] = args[0].substring(1);
490-
var pb = new ProcessBuilder(Arrays.asList(args));
491-
pb.directory(getLcwd().toFile());
492-
pb.redirectErrorStream(true);
493-
Process p = pb.start();
494490
try {
495-
var thread = new Thread() {
496-
public void run() {
497-
var b = new byte[256];
498-
var in = terminal.input();
499-
var out = p.getOutputStream();
500-
int r;
501-
try {
502-
while( ( r = in.read(b)) != -1) {
503-
out.write(b, 0, r);
504-
out.flush();
491+
var pb = new ProcessBuilder(Arrays.asList(args));
492+
pb.directory(getLcwd().toFile());
493+
pb.redirectErrorStream(true);
494+
Process p = pb.start();
495+
try {
496+
var thread = new Thread() {
497+
public void run() {
498+
var b = new byte[256];
499+
var in = terminal.input();
500+
var out = p.getOutputStream();
501+
int r;
502+
try {
503+
while( ( r = in.read(b)) != -1) {
504+
out.write(b, 0, r);
505+
out.flush();
506+
}
507+
}
508+
catch(Exception ioe) {
505509
}
506510
}
507-
catch(Exception ioe) {
508-
}
511+
};
512+
thread.start();
513+
try {
514+
p.getInputStream().transferTo(System.out);
515+
}
516+
finally {
517+
thread.interrupt();
509518
}
510-
};
511-
thread.start();
512-
try {
513-
p.getInputStream().transferTo(System.out);
514519
}
515520
finally {
516-
thread.interrupt();
521+
if(p.waitFor() != 0) {
522+
error(String.format("%s exited with error code %d.%n", args[0], p.exitValue()));
523+
}
517524
}
518525
}
519-
finally {
520-
if(p.waitFor() != 0) {
521-
error(String.format("%s exited with error code %d.", args[0], p.exitValue()));
522-
}
526+
catch(IOException ioe) {
527+
error(String.format("Command %s failed. %s%n", args[0], ioe.getMessage()));
523528
}
524529
}
525530
else {

cli/src/main/java/uk/co/bithatch/tnfs/cli/commands/Bye.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,12 @@ public Bye() {
3737

3838
@Override
3939
protected Integer onCall() throws Exception {
40-
getContainer().getMount().close();
41-
System.exit(0);
40+
try {
41+
getContainer().getMount().close();
42+
}
43+
finally {
44+
System.exit(0);
45+
}
4246
return 0;
4347
}
4448
}

client/src/main/java/uk/co/bithatch/tnfs/client/AbstractTNFSMount.java

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -409,12 +409,27 @@ public void close() throws IOException {
409409
@Override
410410
public int write(ByteBuffer src) throws IOException {
411411
var max = client.payloadSize - 3;
412-
if(src.remaining() > max) {
413-
throw new IllegalArgumentException("Source buffer must provider fewer than " + max + " bytes");
412+
var wrtn = 0;
413+
414+
while(src.hasRemaining()) {
415+
var waslimit = -1;
416+
if(src.remaining() > max) {
417+
waslimit = src.limit();
418+
src.limit(src.position() + max);
419+
// throw new IllegalArgumentException("Source buffer must provider fewer than " + max + " bytes");
420+
}
421+
422+
423+
var w = client.sendMessage(Command.WRITE,
424+
Message.of(sessionId(), Command.WRITE,
425+
new Command.Write(fh.handle(), src)), path).written();
426+
wrtn += w;
427+
if(waslimit > -1) {
428+
src.limit(waslimit);
429+
}
414430
}
415-
var w = client.sendMessage(Command.WRITE, Message.of(sessionId(), Command.WRITE, new Command.Write(fh.handle(), src)), path).written();
416-
position += w;
417-
return w;
431+
position += wrtn;
432+
return wrtn;
418433
}
419434

420435
@Override
@@ -517,8 +532,12 @@ public final void close() throws IOException {
517532
for(var x : extensions.values()) {
518533
x.close();
519534
}
520-
client.sendMessage(Command.UMOUNT, Message.of(sessionId(), Command.UMOUNT, new Command.HeaderOnly()));
521-
onClose();
535+
536+
try {
537+
client.sendMessage(Command.UMOUNT, Message.of(sessionId(), Command.UMOUNT, new Command.HeaderOnly()));
538+
} finally {
539+
onClose();
540+
}
522541
}
523542

524543
protected void beforeClose() throws IOException {

0 commit comments

Comments
 (0)