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
This commit is contained in:
@@ -99,7 +99,16 @@ class _SftpPageState extends ConsumerState<SftpPage> 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')) {
|
||||
|
||||
Reference in New Issue
Block a user