fixes for Windows compatability, test added

This commit is contained in:
jmacxx 2022-01-07 19:42:24 -06:00
parent 9334cffc89
commit 3ea1543882
No known key found for this signature in database
GPG key ID: 155297BABFE94A1B
2 changed files with 15 additions and 1 deletions

View file

@ -49,7 +49,7 @@ public class FileTransferSender extends FileTransferSession {
try {
Map<String, String> env = new HashMap<>();
env.put("create", "true");
FileSystem zipfs = FileSystems.newFileSystem(URI.create("jar:file:" + zipFilePath), env);
FileSystem zipfs = FileSystems.newFileSystem(URI.create("jar:file:///" + (zipFilePath.replace('\\', '/'))), env);
Files.createDirectory(zipfs.getPath(zipId)); // store logfiles in a usefully-named subdir
Stream<Path> paths = Files.walk(Paths.get(Config.appDataDir().toString()), 1);
paths.filter(Files::isRegularFile).forEach(externalTxtFile -> {
@ -79,6 +79,7 @@ public class FileTransferSender extends FileTransferSession {
networkNode.addMessageListener(this);
RandomAccessFile file = new RandomAccessFile(zipFilePath, "r");
expectedFileLength = file.length();
file.close();
// an empty block is sent as request to initiate file transfer, peer must ACK for transfer to continue
dataAwaitingAck = Optional.of(new FileTransferPart(networkNode.getNodeAddress(), fullTradeId, traderId, UUID.randomUUID().toString(), expectedFileLength, ByteString.EMPTY));
uploadData();
@ -93,6 +94,7 @@ public class FileTransferSender extends FileTransferSession {
file.seek(fileOffsetBytes);
byte[] buff = new byte[FILE_BLOCK_SIZE];
int nBytesRead = file.read(buff, 0, FILE_BLOCK_SIZE);
file.close();
if (nBytesRead < 0) {
log.info("Success! We have reached the EOF, {} bytes sent. Removing zip file {}", fileOffsetBytes, zipFilePath);
Files.delete(Paths.get(zipFilePath));

View file

@ -6,6 +6,7 @@ import bisq.network.p2p.network.NetworkNode;
import bisq.common.config.Config;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
@ -41,6 +42,17 @@ public class FileTransferSessionTest implements FileTransferSession.FtpCallback
Assert.assertEquals(1, progressInvocations);
}
@Test
public void testCreateZip() {
FileTransferSender sender = new FileTransferSender(networkNode, counterpartyNodeAddress, testTradeId, testTraderId, testClientId, this);
Assert.assertEquals(0.0, notedProgressPct, 0.0);
Assert.assertEquals(1, progressInvocations);
sender.createZipFileToSend();
File file = new File(sender.zipFilePath);
Assert.assertTrue(file.exists());
Assert.assertTrue(file.length() > 0);
}
@Test
public void testSendInitialize() {
// checks that the initial send request packet contains correct information