diff --git a/3rdparty/deepin-pdfium/src/dpdfdoc.cpp b/3rdparty/deepin-pdfium/src/dpdfdoc.cpp index d1e22586..fd668b0a 100755 --- a/3rdparty/deepin-pdfium/src/dpdfdoc.cpp +++ b/3rdparty/deepin-pdfium/src/dpdfdoc.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include /** @@ -232,6 +233,19 @@ bool DPdfDoc::isLinearized(const QString &fileName) static QFile saveWriter; +static bool isNetworkFileSystem(const QString &path) +{ + if (path.contains(QLatin1String("/gvfs/"))) + return true; + + QStorageInfo storage(path); + QByteArray fsType = storage.fileSystemType(); + if (fsType.contains("cifs") || fsType.contains("smb") || fsType.contains("fuse.gvfs")) + return true; + + return false; +} + int writeFile(struct FPDF_FILEWRITE_* pThis, const void *pData, unsigned long size) { Q_UNUSED(pThis) @@ -309,7 +323,8 @@ bool DPdfDoc::save() } newFile.flush(); // Flush user buffer to kernel buffer - fsync(newFile.handle()); // Sync kernel buffer to disk + if (!isNetworkFileSystem(targetPath)) + fsync(newFile.handle()); // Sync kernel buffer to disk (skip on network FS to avoid UI freeze) newFile.close(); // Remove backup file after successful write @@ -336,7 +351,8 @@ bool DPdfDoc::saveAs(const QString &filePath) locker.unlock(); saveWriter.flush(); // Flush user buffer to kernel buffer - fsync(saveWriter.handle()); // Sync kernel buffer to disk + if (!isNetworkFileSystem(filePath)) + fsync(saveWriter.handle()); // Sync kernel buffer to disk (skip on network FS to avoid UI freeze) saveWriter.close(); return result; diff --git a/tests/document/ut_networkfilesystem.cpp b/tests/document/ut_networkfilesystem.cpp new file mode 100644 index 00000000..2343f1d1 --- /dev/null +++ b/tests/document/ut_networkfilesystem.cpp @@ -0,0 +1,57 @@ +// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: GPL-3.0-or-later + +#include + +#include +#include +#include +#include + +// Replicate the static helper from dpdfdoc.cpp for unit testing. +// The original isNetworkFileSystem() is file-local (static) in +// 3rdparty/deepin-pdfium/src/dpdfdoc.cpp and cannot be linked from +// test code; this copy verifies the decision logic. +static bool isNetworkFileSystem(const QString &path) +{ + if (path.contains(QLatin1String("/gvfs/"))) + return true; + + QStorageInfo storage(path); + QByteArray fsType = storage.fileSystemType(); + if (fsType.contains("cifs") || fsType.contains("smb") || fsType.contains("fuse.gvfs")) + return true; + + return false; +} + +TEST(TestNetworkFileSystem, LocalPathIsNotNetwork) +{ + QTemporaryFile tmp; + ASSERT_TRUE(tmp.open()); + EXPECT_FALSE(isNetworkFileSystem(tmp.fileName())); +} + +TEST(TestNetworkFileSystem, GvfsPathIsNetwork) +{ + QString gvfsPath = QStringLiteral("/run/user/1000/gvfs/smb-share:server=fileserver,share=public/doc.pdf"); + EXPECT_TRUE(isNetworkFileSystem(gvfsPath)); +} + +TEST(TestNetworkFileSystem, RootIsNotNetwork) +{ + EXPECT_FALSE(isNetworkFileSystem(QStringLiteral("/"))); +} + +TEST(TestNetworkFileSystem, TmpDirIsNotNetwork) +{ + EXPECT_FALSE(isNetworkFileSystem(QStringLiteral("/tmp"))); +} + +int main(int argc, char **argv) +{ + QCoreApplication app(argc, argv); + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +}