mirror of
https://github.com/TermoraDev/termora.git
synced 2026-01-16 02:12:58 +08:00
fix: SFTP add transport NPE
This commit is contained in:
@@ -680,7 +680,7 @@ class FileSystemViewTable(
|
||||
|
||||
coroutineScope.launch {
|
||||
try {
|
||||
doTransfer(arrayOf(attr), fromLocalSystem, targetWorkdir)
|
||||
doTransfer(attr, fromLocalSystem, targetWorkdir)
|
||||
} catch (e: Exception) {
|
||||
if (log.isErrorEnabled) {
|
||||
log.error(e.message, e)
|
||||
@@ -829,17 +829,12 @@ class FileSystemViewTable(
|
||||
* 开始查找所有子,查找到之后立即添加任务,如果添加失败(任意一个)那么立即终止
|
||||
*/
|
||||
private fun doTransfer(
|
||||
attrs: Array<FileSystemViewTableModel.Attr>,
|
||||
attr: FileSystemViewTableModel.Attr,
|
||||
fromLocalSystem: Boolean,
|
||||
targetWorkdir: Path?
|
||||
) {
|
||||
if (attrs.isEmpty()) return
|
||||
val sftpPanel = this.sftpPanel
|
||||
val target = sftpPanel.getTarget(table) ?: return
|
||||
var isTerminate = false
|
||||
val queue = ArrayDeque<Transport>()
|
||||
|
||||
for (attr in attrs) {
|
||||
|
||||
/**
|
||||
* 定义一个添加器,它可以自动的判断导入/拖拽行为
|
||||
@@ -858,13 +853,12 @@ class FileSystemViewTable(
|
||||
|
||||
if (attr.isFile) {
|
||||
if (!adder.add(createTransport(attr.path, false, 0).apply { scanned() })) {
|
||||
isTerminate = true
|
||||
break
|
||||
return
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
queue.clear()
|
||||
val queue = ArrayDeque<Transport>()
|
||||
var isTerminate = false
|
||||
|
||||
try {
|
||||
walk(attr.path, object : FileVisitor<Path> {
|
||||
@@ -900,9 +894,6 @@ class FileSystemViewTable(
|
||||
isTerminate = true
|
||||
}
|
||||
|
||||
if (isTerminate) break
|
||||
}
|
||||
|
||||
if (isTerminate) {
|
||||
// 把剩余的文件夹标记为扫描完毕
|
||||
while (queue.isNotEmpty()) queue.removeLast().scanned()
|
||||
@@ -960,7 +951,11 @@ class FileSystemViewTable(
|
||||
targetWorkdir: Path?,
|
||||
transport: Transport
|
||||
): Boolean {
|
||||
return sftpPanel.addTransport(table, sourceWorkdir, target, targetWorkdir, transport)
|
||||
return try {
|
||||
sftpPanel.addTransport(table, sourceWorkdir, target, targetWorkdir, transport)
|
||||
} catch (e: Exception) {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
private fun createTransport(source: Path, isDirectory: Boolean, parentId: Long): Transport {
|
||||
|
||||
@@ -12,8 +12,10 @@ import org.jdesktop.swingx.treetable.DefaultMutableTreeTableNode
|
||||
import org.jdesktop.swingx.treetable.DefaultTreeTableModel
|
||||
import org.jdesktop.swingx.treetable.MutableTreeTableNode
|
||||
import org.slf4j.LoggerFactory
|
||||
import java.util.*
|
||||
import java.util.concurrent.locks.ReentrantLock
|
||||
import javax.swing.SwingUtilities
|
||||
import kotlin.collections.ArrayDeque
|
||||
import kotlin.io.path.name
|
||||
import kotlin.math.abs
|
||||
import kotlin.math.max
|
||||
@@ -27,7 +29,7 @@ class TransportTableModel(private val coroutineScope: CoroutineScope) :
|
||||
|
||||
val lock = ReentrantLock()
|
||||
|
||||
private val transports = linkedMapOf<Long, TransportTreeTableNode>()
|
||||
private val transports = Collections.synchronizedMap(linkedMapOf<Long, TransportTreeTableNode>())
|
||||
private val reporter = SpeedReporter(coroutineScope)
|
||||
private var listeners = emptyArray<TransportListener>()
|
||||
private val activeTransports = linkedMapOf<Long, Job>()
|
||||
@@ -104,8 +106,15 @@ class TransportTableModel(private val coroutineScope: CoroutineScope) :
|
||||
transports[transport.id] = newNode
|
||||
|
||||
if ((transports.containsKey(parentId) || p == root) && transports.containsKey(transport.id)) {
|
||||
// 同步加入节点
|
||||
SwingUtilities.invokeLater { insertNodeInto(newNode, p, p.childCount) }
|
||||
// 主线程加入节点
|
||||
SwingUtilities.invokeLater {
|
||||
// 因为是异步的,父节点此时可能已经被移除了
|
||||
if (p == root || transports.containsKey(parentId)) {
|
||||
insertNodeInto(newNode, p, p.childCount)
|
||||
} else {
|
||||
removeTransport(transport.id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return@withLock true
|
||||
|
||||
Reference in New Issue
Block a user