Skip to content

Commit 989f19d

Browse files
authored
edits: handle eperm in file edit checks (#1217)
Closes microsoft/vscode-internalbacklog#5824
1 parent 6f47383 commit 989f19d

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

src/extension/tools/node/editFileToolUtils.tsx

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { extUriBiasedIgnorePathCase, normalizePath, relativePath } from '../../.
2323
import { URI } from '../../../util/vs/base/common/uri';
2424
import { Position as EditorPosition } from '../../../util/vs/editor/common/core/position';
2525
import { ServicesAccessor } from '../../../util/vs/platform/instantiation/common/instantiation';
26-
import { EndOfLine, MarkdownString, Position, Range, TextEdit } from '../../../vscodeTypes';
26+
import { EndOfLine, Position, Range, TextEdit } from '../../../vscodeTypes';
2727

2828
// Simplified Hunk type for the patch
2929
interface Hunk {
@@ -561,9 +561,10 @@ const platformConfirmationRequiredPaths = (
561561

562562
const enum ConfirmationCheckResult {
563563
NoConfirmation,
564+
NoPermissions,
564565
Sensitive,
565566
SystemFile,
566-
OutsideWorkspace
567+
OutsideWorkspace,
567568
}
568569

569570
/**
@@ -624,6 +625,9 @@ function makeUriConfirmationChecker(configuration: IConfigurationService, worksp
624625
toCheck.push(URI.file(linked));
625626
}
626627
} catch (e) {
628+
if ((e as NodeJS.ErrnoException).code === 'EPERM') {
629+
return ConfirmationCheckResult.NoPermissions;
630+
}
627631
// Usually EPERM or ENOENT on the linkedFile
628632
}
629633
}
@@ -648,17 +652,21 @@ export async function createEditConfirmation(accessor: ServicesAccessor, uris: r
648652
return '`' + (wf ? relativePath(wf, uri) : uri.fsPath) + '`';
649653
}).join(', ');
650654

655+
let message: string;
656+
if (needsConfirmation.some(r => r.reason === ConfirmationCheckResult.NoPermissions)) {
657+
message = t`The model wants to edit files you don't have permission to modify (${fileParts}).`;
658+
} else if (needsConfirmation.some(r => r.reason === ConfirmationCheckResult.Sensitive)) {
659+
message = t`The model wants to edit sensitive files (${fileParts}).`;
660+
} else if (needsConfirmation.some(r => r.reason === ConfirmationCheckResult.OutsideWorkspace)) {
661+
message = t`The model wants to edit files outside of your workspace (${fileParts}).`;
662+
} else {
663+
message = t`The model wants to edit system files (${fileParts}).`;
664+
}
665+
651666
return {
652667
confirmationMessages: {
653668
title: t('Allow edits to sensitive files?'),
654-
message: new MarkdownString(
655-
(needsConfirmation.some(r => r.reason === ConfirmationCheckResult.Sensitive)
656-
? t`The model wants to edit sensitive files (${fileParts}).`
657-
: needsConfirmation.some(r => r.reason === ConfirmationCheckResult.OutsideWorkspace)
658-
? t`The model wants to edit files outside of your workspace (${fileParts}).`
659-
: t`The model wants to edit system files (${fileParts}).`)
660-
+ ' ' + t`Do you want to allow this?` + '\n\n' + asString()
661-
),
669+
message: message + ' ' + t`Do you want to allow this?` + '\n\n' + asString(),
662670
}
663671
};
664672
}

0 commit comments

Comments
 (0)