mirror of
https://github.com/RooVetGit/Roo-Code.git
synced 2026-08-28 05:27:24 +00:00
fix: create parent directories before checking file existence in write_to_file tool
Fixes ENOENT errors when attempting to create files in non-existent subdirectories. The tool now ensures parent directories are created with recursive mkdir before checking if a file exists, preventing "No such file or directory" errors. Fixes #9634
This commit is contained in:
parent
ba09228015
commit
7d7979ac38
1 changed files with 16 additions and 0 deletions
|
|
@ -75,6 +75,14 @@ export class WriteToFileTool extends BaseTool<"write_to_file"> {
|
|||
fileExists = task.diffViewProvider.editType === "modify"
|
||||
} else {
|
||||
const absolutePath = path.resolve(task.cwd, relPath)
|
||||
// Ensure parent directories exist before checking file existence
|
||||
const dirPath = path.dirname(absolutePath)
|
||||
try {
|
||||
await fs.mkdir(dirPath, { recursive: true })
|
||||
} catch (dirError) {
|
||||
// Ignore errors - directory might already exist or other issues
|
||||
// The important thing is we tried to create it
|
||||
}
|
||||
fileExists = await fileExistsAtPath(absolutePath)
|
||||
task.diffViewProvider.editType = fileExists ? "modify" : "create"
|
||||
}
|
||||
|
|
@ -311,6 +319,14 @@ export class WriteToFileTool extends BaseTool<"write_to_file"> {
|
|||
fileExists = task.diffViewProvider.editType === "modify"
|
||||
} else {
|
||||
const absolutePath = path.resolve(task.cwd, relPath)
|
||||
// Ensure parent directories exist before checking file existence
|
||||
const dirPath = path.dirname(absolutePath)
|
||||
try {
|
||||
await fs.mkdir(dirPath, { recursive: true })
|
||||
} catch (dirError) {
|
||||
// Ignore errors - directory might already exist or other issues
|
||||
// The important thing is we tried to create it
|
||||
}
|
||||
fileExists = await fileExistsAtPath(absolutePath)
|
||||
task.diffViewProvider.editType = fileExists ? "modify" : "create"
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue