Skip to content

Commit 6aaccd8

Browse files
committed
chore: Add safety check before copying workflow files
- Add check to delete existing workflow directory before copying new files - Improve code indentation and readability - Update workflow installation logic for safer file operations
1 parent ba7d38f commit 6aaccd8

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

src/main/kotlin/ai/devchat/plugin/DevChatToolWindowFactory.kt

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -210,25 +210,29 @@ class DevChatToolWindowFactory : ToolWindowFactory, DumbAware, Disposable {
210210
devChatService.pythonReady = true
211211
}
212212

213-
private suspend fun installWorkflows(): Boolean {
214-
Log.info("Start checking and copying workflows files")
215-
val workflowMericoDir = File(PathUtils.workflowMericoPath)
216-
var updatePublicWorkflows = CONFIG["update_public_workflow"]
217-
val overwrite = devChatVersion != DevChatState.instance.lastVersion
218-
219-
var workflowCopied = false;
220-
if ((overwrite && updatePublicWorkflows == false) || !workflowMericoDir.exists() || !workflowMericoDir.isDirectory || workflowMericoDir.listFiles()?.isEmpty() == true) {
221-
Log.info("Workflow Merico directory is missing or empty. Creating and populating it.")
222-
PathUtils.copyResourceDirToPath("/workflows", PathUtils.workflowPath, true)
223-
workflowCopied = true;
224-
} else {
225-
Log.info("Workflow Merico directory exists and is not empty. Skipping copy.")
213+
private suspend fun installWorkflows(): Boolean {
214+
Log.info("Start checking and copying workflows files")
215+
val workflowMericoDir = File(PathUtils.workflowMericoPath)
216+
var updatePublicWorkflows = CONFIG["update_public_workflow"]
217+
val overwrite = devChatVersion != DevChatState.instance.lastVersion
218+
219+
var workflowCopied = false;
220+
if ((overwrite && updatePublicWorkflows == false) || !workflowMericoDir.exists() || !workflowMericoDir.isDirectory || workflowMericoDir.listFiles()?.isEmpty() == true) {
221+
Log.info("Workflow Merico directory is missing or empty. Creating and populating it.")
222+
// 安全删除:先检查是否存在
223+
if (workflowMericoDir.exists()) {
224+
workflowMericoDir.deleteRecursively()
226225
}
227-
228-
Log.info("Finished checking and copying workflows files")
229-
return workflowCopied;
226+
PathUtils.copyResourceDirToPath("/workflows", PathUtils.workflowPath, true)
227+
workflowCopied = true;
228+
} else {
229+
Log.info("Workflow Merico directory exists and is not empty. Skipping copy.")
230230
}
231231

232+
Log.info("Finished checking and copying workflows files")
233+
return workflowCopied;
234+
}
235+
232236
private suspend fun installTools() {
233237
val overwrite = devChatVersion != DevChatState.instance.lastVersion
234238
Log.info("start to copy tools files")

0 commit comments

Comments
 (0)