Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions lib/view/page/storage/sftp.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class _SftpPageState extends ConsumerState<SftpPage> with AfterLayoutMixin {
_SortOption? _sortedFilesOption;
bool? _sortedFilesShowFoldersFirst;
List<SftpName>? _sortedFilesCache;
Future<SftpClient>? _openingClientFuture;

bool get _useSudo => _sudoHelper.enabled && _sudoMode.value;

Expand All @@ -84,9 +85,11 @@ class _SftpPageState extends ConsumerState<SftpPage> with AfterLayoutMixin {

@override
void dispose() {
super.dispose();
_status.client?.close();
_openingClientFuture = null;
_sortOption.dispose();
_sudoMode.dispose();
super.dispose();
}

@override
Expand Down Expand Up @@ -1033,17 +1036,23 @@ extension _Actions on _SftpPageState {
}

try {
_status.client ??= await _withSftpOpTimeout(
'open browser session',
_client.sftp(),
);
if (_status.client == null && _openingClientFuture == null) {
_openingClientFuture = _withSftpOpTimeout(
'open browser session',
_client.sftp(),
);
}
_status.client ??= await _openingClientFuture;
_openingClientFuture = null;
if (!mounted) return null;
final client = _status.client;
if (client == null) return null;
return await _withSftpOpTimeout(
'list directory',
client.listdir(listPath),
);
} on SftpStatusError catch (e) {
_openingClientFuture = null;
final canFallback =
_sudoHelper.enabled &&
(e.code == 3 || _sftpPermissionDeniedReg.hasMatch(e.message));
Expand All @@ -1054,6 +1063,13 @@ extension _Actions on _SftpPageState {
final items = await _sudoHelper.listDir(listPath, password: pwd);
_sudoMode.value = true;
return items;
} catch (e) {
if (e is! SftpStatusError) {
_status.client?.close();
_status.client = null;
}
_openingClientFuture = null;
rethrow;
}
}

Expand Down