From 728116e11ff24818cc71a28249402e6362f868c6 Mon Sep 17 00:00:00 2001 From: GT610 <79314033+GT-610@users.noreply.github.com> Date: Thu, 19 Mar 2026 20:58:07 +0800 Subject: [PATCH] fix(storage): Fixed an issue with the SFTP path history (#1077) * fix(storage): Fixed an issue with the SFTP path history Added path validity checks when processing the SFTP path history Standardized the format of stored paths and removed extra slashes * refactor(sftp): Standardize SFTP path handling and optimize resource management Extract path normalization logic into a separate method: _normalizeSftpPath Ensure that the SFTP client is properly closed after use --- lib/view/page/storage/sftp.dart | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/view/page/storage/sftp.dart b/lib/view/page/storage/sftp.dart index 4c7279bf..18f49575 100644 --- a/lib/view/page/storage/sftp.dart +++ b/lib/view/page/storage/sftp.dart @@ -99,7 +99,16 @@ class _SftpPageState extends ConsumerState with AfterLayoutMixin { if (Stores.setting.sftpOpenLastPath.fetch()) { final history = Stores.history.sftpLastPath.fetch(widget.args.spi.id); if (history != null) { - initPath = history; + SftpClient? sftp; + try { + final normalizedHistory = _normalizeSftpPath(history); + sftp = await _client.sftp(); + await sftp.listdir(normalizedHistory); + initPath = normalizedHistory; + } catch (_) { + } finally { + sftp?.close(); + } } } @@ -639,7 +648,8 @@ extension _Actions on _SftpPageState { // Only update history when success if (Stores.setting.sftpOpenLastPath.fetch()) { - Stores.history.sftpLastPath.put(widget.args.spi.id, listPath); + final normalizedPath = _normalizeSftpPath(listPath); + Stores.history.sftpLastPath.put(widget.args.spi.id, normalizedPath); } return true; @@ -789,6 +799,8 @@ extension _Actions on _SftpPageState { } } +String _normalizeSftpPath(String path) => path.replaceAll(RegExp(r'/+'), '/'); + String? _getDecompressCmd(String filename) { for (final ext in _extCmdMap.keys) { if (filename.endsWith('.$ext')) {