Skip to content

Commit

Permalink
fix: handle missing recent file initialization
Browse files Browse the repository at this point in the history
When the recent file manager starts, it now properly handles the case
where the xbel file doesn't exist. This fix:

- Add existence check for xbel file
- Create empty xbel file if not exists
- Add proper error handling and logging
- Ensure file watcher starts correctly

This ensures the recent file manager works properly on first run or
when the xbel file is missing.

Log:

Bug: https://pms.uniontech.com/bug-view-296569.html
  • Loading branch information
Johnson-zs committed Dec 24, 2024
1 parent 61bd82f commit ba0115d
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/plugins/server/serverplugin-recentdaemon/recentmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

#include <QCoreApplication>
#include <QTimer>
#include <QFileInfo>
#include <QFile>

SERVERRECENTMANAGER_BEGIN_NAMESPACE

Expand Down Expand Up @@ -78,6 +80,20 @@ void RecentManager::finalize()
void RecentManager::startWatch()
{
auto uri { QUrl::fromLocalFile(xbelPath()) };
QString localPath = uri.toLocalFile();

if (!QFileInfo(localPath).exists()) {
// Create empty xbel file if not exists
QFile file(localPath);
if (file.open(QIODevice::WriteOnly)) {
fmInfo() << "Created empty recent file:" << localPath;
file.close();
} else {
fmWarning() << "Failed to create recent file:" << localPath;
return;
}
}

watcher = WatcherFactory::create<AbstractFileWatcher>(uri);
fmDebug() << "Start watch recent file: " << uri;
// fileAttributeChanged 可能被高频率发送
Expand Down

0 comments on commit ba0115d

Please sign in to comment.