From cc300c141aaeb4a9f1487e0d24494fc48917671d Mon Sep 17 00:00:00 2001 From: GT610 <79314033+GT-610@users.noreply.github.com> Date: Tue, 6 Jan 2026 23:50:11 +0800 Subject: [PATCH] refactor(sftp): Replace hard-coded path separators with Pfs.seperator (#993) Unify the use of Pfs.seperator for handling file path separators to enhance cross-platform compatibility. --- lib/data/model/sftp/req.dart | 2 +- lib/data/model/sftp/worker.dart | 2 +- lib/view/page/storage/local.dart | 6 +++--- lib/view/page/storage/sftp.dart | 6 +++++- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/data/model/sftp/req.dart b/lib/data/model/sftp/req.dart index d9c769ef..aafe2155 100644 --- a/lib/data/model/sftp/req.dart +++ b/lib/data/model/sftp/req.dart @@ -36,7 +36,7 @@ class SftpReqStatus { late SftpWorker worker; final Completer? completer; - String get fileName => req.localPath.split('/').last; + String get fileName => req.localPath.split(Pfs.seperator).last; // status of the download double? progress; diff --git a/lib/data/model/sftp/worker.dart b/lib/data/model/sftp/worker.dart index 654deca9..7449c4f0 100644 --- a/lib/data/model/sftp/worker.dart +++ b/lib/data/model/sftp/worker.dart @@ -70,7 +70,7 @@ Future _download(SftpReq req, SendPort mainSendPort, SendErrorFunction sen mainSendPort.send(SftpWorkerStatus.sshConnectted); /// Create the directory if not exists - final dirPath = req.localPath.substring(0, req.localPath.lastIndexOf('/')); + final dirPath = req.localPath.substring(0, req.localPath.lastIndexOf(Pfs.seperator)); await Directory(dirPath).create(recursive: true); /// Use [FileMode.write] to overwrite the file diff --git a/lib/view/page/storage/local.dart b/lib/view/page/storage/local.dart index 1c2be656..b00362a7 100644 --- a/lib/view/page/storage/local.dart +++ b/lib/view/page/storage/local.dart @@ -123,7 +123,7 @@ class _LocalFilePageState extends ConsumerState with AutomaticKee final item = items![index]; final file = item.$1; - final fileName = file.path.split('/').last; + final fileName = file.path.split(Pfs.seperator).last; final stat = item.$2; final isDir = stat.type == FileSystemEntityType.directory; @@ -216,7 +216,7 @@ extension _Actions on _LocalFilePageState { } Future _showFileActionDialog(FileSystemEntity file) async { - final fileName = file.path.split('/').lastOrNull ?? ''; + final fileName = file.path.split(Pfs.seperator).lastOrNull ?? ''; if (isPickFile) { context.showRoundDialog( title: libL10n.file, @@ -308,7 +308,7 @@ extension _Actions on _LocalFilePageState { } void _showDeleteDialog(FileSystemEntity file) { - final fileName = file.path.split('/').last; + final fileName = file.path.split(Pfs.seperator).last; context.showRoundDialog( title: libL10n.delete, child: Text(libL10n.askContinue('${libL10n.delete} $fileName')), diff --git a/lib/view/page/storage/sftp.dart b/lib/view/page/storage/sftp.dart index 89a24751..7c405cf0 100644 --- a/lib/view/page/storage/sftp.dart +++ b/lib/view/page/storage/sftp.dart @@ -585,7 +585,11 @@ extension _Actions on _SftpPageState { /// Local file dir + server id + remote path String _getLocalPath(String remotePath) { - return Paths.file.joinPath(widget.args.spi.oldId).joinPath(remotePath); + var normalizedPath = remotePath.replaceAll('/', Pfs.seperator); + if (normalizedPath.startsWith(Pfs.seperator)) { + normalizedPath = normalizedPath.substring(1); + } + return Paths.file.joinPath(widget.args.spi.id).joinPath(normalizedPath); } /// Only return true if the path is changed