Skip to content

Commit 6e8644a

Browse files
authored
🐛 同步修复文件删除bug导致的死锁问题和增加更多的日志 (#1136)
1 parent b455724 commit 6e8644a

File tree

2 files changed

+21
-24
lines changed

2 files changed

+21
-24
lines changed

packages/filesystem/googledrive/googledrive.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ export default class GoogleDriveFileSystem implements FileSystem {
145145
// 首先,找到要删除的文件或文件夹
146146
const fileId = await this.getFileId(fullPath);
147147
if (!fileId) {
148-
throw new Error(`File or directory not found: ${path}`);
148+
throw new Error(`File or directory not found: ${fullPath}`);
149149
}
150150

151151
// 删除文件或文件夹

src/app/service/service_worker/synchronize.ts

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -394,29 +394,25 @@ export class SynchronizeService {
394394
// 脚本存在但是文件不存在,则读取.meta.json内容判断是否需要删除脚本
395395
if (!file.script) {
396396
result.push(
397-
new Promise((resolve) => {
398-
const handler = async () => {
399-
// 读取meta文件
400-
const meta = await fs.open(file.meta!);
401-
const metaJson = (await meta.read("string")) as string;
402-
const metaObj = JSON.parse(metaJson) as SyncMeta;
403-
if (metaObj.isDeleted) {
404-
if (script) {
405-
this.script.deleteScript(script.uuid);
406-
InfoNotification(
407-
i18n.t("notification.script_sync_delete"),
408-
i18n.t("notification.script_sync_delete_desc", { scriptName: i18nName(script) })
409-
);
410-
}
411-
scriptMap.delete(uuid);
412-
} else {
413-
// 否则认为是一个无效的.meta文件,进行删除
414-
await fs.delete(file.meta!.path);
397+
(async () => {
398+
// 读取meta文件
399+
const meta = await fs.open(file.meta!);
400+
const metaJson = (await meta.read("string")) as string;
401+
const metaObj = JSON.parse(metaJson) as SyncMeta;
402+
if (metaObj.isDeleted) {
403+
if (script) {
404+
this.script.deleteScript(script.uuid);
405+
InfoNotification(
406+
i18n.t("notification.script_sync_delete"),
407+
i18n.t("notification.script_sync_delete_desc", { scriptName: i18nName(script) })
408+
);
415409
}
416-
resolve();
417-
};
418-
handler();
419-
})
410+
scriptMap.delete(uuid);
411+
} else {
412+
// 否则认为是一个无效的.meta文件,进行删除
413+
await fs.delete(file.meta!.name);
414+
}
415+
})()
420416
);
421417
return;
422418
}
@@ -503,9 +499,10 @@ export class SynchronizeService {
503499
// 保存脚本猫同步状态
504500
const syncFile = await fs.create("scriptcat-sync.json");
505501
await syncFile.write(JSON.stringify(scriptcatSync, null, 2));
506-
this.logger.info("sync scriptcat sync file success");
502+
this.logger.info("sync scriptcat-sync.json file success");
507503
}
508504
// 重新获取文件列表,保存文件摘要
505+
this.logger.info("update file digest");
509506
await this.updateFileDigest(fs);
510507
this.logger.info("sync complete");
511508
return;

0 commit comments

Comments
 (0)