forked from RooCodeInc/Roo-Code
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathpathUtils.ts
More file actions
24 lines (21 loc) · 967 Bytes
/
pathUtils.ts
File metadata and controls
24 lines (21 loc) · 967 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import * as vscode from "vscode"
import * as path from "path"
/**
* Checks if a file path is outside all workspace folders
* @param filePath The file path to check
* @returns true if the path is outside all workspace folders, false otherwise
*/
export function isPathOutsideWorkspace(filePath: string): boolean {
// If there are no workspace folders, consider everything outside workspace for safety
if (!vscode.workspace.workspaceFolders || vscode.workspace.workspaceFolders.length === 0) {
return true
}
// Normalize and resolve the path to handle .. and . components correctly
const absolutePath = path.resolve(filePath)
// Check if the path is within any workspace folder
return !vscode.workspace.workspaceFolders.some((folder) => {
const folderPath = folder.uri.fsPath
// Path is inside a workspace if it equals the workspace path or is a subfolder
return absolutePath === folderPath || absolutePath.startsWith(folderPath + path.sep)
})
}