Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Add safety check before copying workflow files #216

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 20 additions & 16 deletions src/main/kotlin/ai/devchat/plugin/DevChatToolWindowFactory.kt
Original file line number Diff line number Diff line change
Expand Up @@ -210,25 +210,29 @@ class DevChatToolWindowFactory : ToolWindowFactory, DumbAware, Disposable {
devChatService.pythonReady = true
}

private suspend fun installWorkflows(): Boolean {
Log.info("Start checking and copying workflows files")
val workflowMericoDir = File(PathUtils.workflowMericoPath)
var updatePublicWorkflows = CONFIG["update_public_workflow"]
val overwrite = devChatVersion != DevChatState.instance.lastVersion

var workflowCopied = false;
if ((overwrite && updatePublicWorkflows == false) || !workflowMericoDir.exists() || !workflowMericoDir.isDirectory || workflowMericoDir.listFiles()?.isEmpty() == true) {
Log.info("Workflow Merico directory is missing or empty. Creating and populating it.")
PathUtils.copyResourceDirToPath("/workflows", PathUtils.workflowPath, true)
workflowCopied = true;
} else {
Log.info("Workflow Merico directory exists and is not empty. Skipping copy.")
private suspend fun installWorkflows(): Boolean {
Log.info("Start checking and copying workflows files")
val workflowMericoDir = File(PathUtils.workflowMericoPath)
var updatePublicWorkflows = CONFIG["update_public_workflow"]
val overwrite = devChatVersion != DevChatState.instance.lastVersion

var workflowCopied = false;
if ((overwrite && updatePublicWorkflows == false) || !workflowMericoDir.exists() || !workflowMericoDir.isDirectory || workflowMericoDir.listFiles()?.isEmpty() == true) {
Log.info("Workflow Merico directory is missing or empty. Creating and populating it.")
// 安全删除:先检查是否存在
if (workflowMericoDir.exists()) {
workflowMericoDir.deleteRecursively()
}

Log.info("Finished checking and copying workflows files")
return workflowCopied;
PathUtils.copyResourceDirToPath("/workflows", PathUtils.workflowPath, true)
workflowCopied = true;
} else {
Log.info("Workflow Merico directory exists and is not empty. Skipping copy.")
}

Log.info("Finished checking and copying workflows files")
return workflowCopied;
}

private suspend fun installTools() {
val overwrite = devChatVersion != DevChatState.instance.lastVersion
Log.info("start to copy tools files")
Expand Down
Loading