mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-08-29 13:17:43 +00:00
Detect data corruption caused by sshfs 3.x and abort transfer
This commit is contained in:
parent
1cfddd409d
commit
83c8a30a71
@ -48,7 +48,10 @@ import org.kde.kdeconnect.Helpers.RandomHelper;
|
|||||||
import org.kde.kdeconnect.Helpers.SecurityHelpers.SslHelper;
|
import org.kde.kdeconnect.Helpers.SecurityHelpers.SslHelper;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.io.RandomAccessFile;
|
||||||
import java.net.Inet4Address;
|
import java.net.Inet4Address;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.NetworkInterface;
|
import java.net.NetworkInterface;
|
||||||
@ -215,6 +218,32 @@ class SimpleSftpServer {
|
|||||||
this.file = file;
|
this.file = file;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public OutputStream createOutputStream(long offset) throws IOException {
|
||||||
|
if (!isWritable()) {
|
||||||
|
throw new IOException("No write permission : " + file.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
final RandomAccessFile raf = new RandomAccessFile(file, "rw");
|
||||||
|
try {
|
||||||
|
if (offset < raf.length()) {
|
||||||
|
throw new IOException("Your SSHFS is bugged"); //SSHFS 3.0 and 3.2 cause data corruption, abort the transfer if this happens
|
||||||
|
}
|
||||||
|
raf.setLength(offset);
|
||||||
|
raf.seek(offset);
|
||||||
|
|
||||||
|
return new FileOutputStream(raf.getFD()) {
|
||||||
|
public void close() throws IOException {
|
||||||
|
super.close();
|
||||||
|
raf.close();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
} catch (IOException e) {
|
||||||
|
raf.close();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean delete() {
|
public boolean delete() {
|
||||||
//Log.e("Sshd", "deleting file");
|
//Log.e("Sshd", "deleting file");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user