mirror of
https://github.com/RooVetGit/Roo-Code.git
synced 2026-08-28 05:27:24 +00:00
refactor(storage): add non-creating path resolution for settings dir; use no-create in migrations and instructions to avoid side effects
This commit is contained in:
parent
a44c30ab86
commit
604a606c74
3 changed files with 21 additions and 12 deletions
|
|
@ -2,13 +2,14 @@ import * as path from "path"
|
|||
import * as vscode from "vscode"
|
||||
|
||||
import { GlobalFileNames } from "../../../shared/globalFileNames"
|
||||
import { getSettingsDirectoryPath } from "../../../utils/storage"
|
||||
import { getStorageBasePath } from "../../../utils/storage"
|
||||
|
||||
export async function createModeInstructions(context: vscode.ExtensionContext | undefined): Promise<string> {
|
||||
if (!context) throw new Error("Missing VSCode Extension Context")
|
||||
|
||||
// Use getSettingsDirectoryPath to respect custom storage path setting
|
||||
const settingsDir = await getSettingsDirectoryPath(context.globalStorageUri.fsPath)
|
||||
// Resolve settings directory without creating it (avoid side effects for help text)
|
||||
const basePath = await getStorageBasePath(context.globalStorageUri.fsPath, false)
|
||||
const settingsDir = path.join(basePath, "settings")
|
||||
const customModesPath = path.join(settingsDir, GlobalFileNames.customModes)
|
||||
|
||||
return `
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import * as path from "path"
|
|||
import * as fs from "fs/promises"
|
||||
import { fileExistsAtPath } from "./fs"
|
||||
import { GlobalFileNames } from "../shared/globalFileNames"
|
||||
import { getSettingsDirectoryPath } from "./storage"
|
||||
import { getStorageBasePath } from "./storage"
|
||||
import * as yaml from "yaml"
|
||||
|
||||
const deprecatedCustomModesJSONFilename = "custom_modes.json"
|
||||
|
|
@ -27,8 +27,9 @@ export async function migrateSettings(
|
|||
]
|
||||
|
||||
try {
|
||||
// Use getSettingsDirectoryPath to respect custom storage path
|
||||
const settingsDir = await getSettingsDirectoryPath(context.globalStorageUri.fsPath)
|
||||
// Resolve settings directory without creating it to preserve early-return behavior
|
||||
const basePath = await getStorageBasePath(context.globalStorageUri.fsPath, false)
|
||||
const settingsDir = path.join(basePath, "settings")
|
||||
|
||||
// Check if settings directory exists first
|
||||
if (!(await fileExistsAtPath(settingsDir))) {
|
||||
|
|
|
|||
|
|
@ -11,7 +11,13 @@ import { t } from "../i18n"
|
|||
* If a custom path is configured, uses that path
|
||||
* Otherwise uses the default VSCode extension global storage path
|
||||
*/
|
||||
export async function getStorageBasePath(defaultPath: string): Promise<string> {
|
||||
/**
|
||||
* Gets the base storage path for conversations
|
||||
* If a custom path is configured, uses that path
|
||||
* Otherwise uses the default VSCode extension global storage path
|
||||
* Optionally avoid creating the directory (create = false) for pure path resolution.
|
||||
*/
|
||||
export async function getStorageBasePath(defaultPath: string, create = true): Promise<string> {
|
||||
// Get user-configured custom storage path
|
||||
let customStoragePath = ""
|
||||
|
||||
|
|
@ -30,11 +36,12 @@ export async function getStorageBasePath(defaultPath: string): Promise<string> {
|
|||
}
|
||||
|
||||
try {
|
||||
// Ensure custom path exists
|
||||
await fs.mkdir(customStoragePath, { recursive: true })
|
||||
|
||||
// Check directory write permission without creating temp files
|
||||
await fs.access(customStoragePath, fsConstants.R_OK | fsConstants.W_OK | fsConstants.X_OK)
|
||||
// When create is requested, ensure the custom path exists and is accessible
|
||||
if (create) {
|
||||
await fs.mkdir(customStoragePath, { recursive: true })
|
||||
// Check directory write permission without creating temp files
|
||||
await fs.access(customStoragePath, fsConstants.R_OK | fsConstants.W_OK | fsConstants.X_OK)
|
||||
}
|
||||
|
||||
return customStoragePath
|
||||
} catch (error) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue