From d67b6fed2fc8e2bc51c452b1d8b4d3e96f6479a7 Mon Sep 17 00:00:00 2001 From: mlhiter <3076438032@qq.com> Date: Wed, 13 Nov 2024 21:11:25 +0800 Subject: [PATCH] fix: path bug --- extensions/ide/vscode/devbox/package.json | 2 +- .../devbox/src/commands/remoteConnector.ts | 12 ++++++++---- extensions/ide/vscode/devbox/src/utils/file.ts | 16 ++++++++++++---- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/extensions/ide/vscode/devbox/package.json b/extensions/ide/vscode/devbox/package.json index 98bc9e533d0..6035deaab69 100644 --- a/extensions/ide/vscode/devbox/package.json +++ b/extensions/ide/vscode/devbox/package.json @@ -2,7 +2,7 @@ "name": "devbox-aio", "displayName": "Devbox", "description": "help code for cloud devbox in sailos/sealos", - "version": "1.0.1", + "version": "1.0.3", "keywords": [ "devbox", "remote development", diff --git a/extensions/ide/vscode/devbox/src/commands/remoteConnector.ts b/extensions/ide/vscode/devbox/src/commands/remoteConnector.ts index 05f8ec7bed4..5f4d29a286a 100644 --- a/extensions/ide/vscode/devbox/src/commands/remoteConnector.ts +++ b/extensions/ide/vscode/devbox/src/commands/remoteConnector.ts @@ -26,10 +26,14 @@ export class RemoteSSHConnector extends Disposable { } private replaceHomePathInConfig(content: string): string { - return content.replace( - /Include ~\/.ssh\/sealos\/devbox_config/g, - `Include ${os.homedir()}/.ssh/sealos/devbox_config` - ) + const includePattern = /Include ~\/.ssh\/sealos\/devbox_config/ + const includeLine = `Include ${os.homedir()}/.ssh/sealos/devbox_config` + + if (includePattern.test(content)) { + return content.replace(includePattern, includeLine) + } else { + return `${includeLine}\n${content}` + } } private sshConfigPreProcess() { diff --git a/extensions/ide/vscode/devbox/src/utils/file.ts b/extensions/ide/vscode/devbox/src/utils/file.ts index 3ab0193367d..796cb89a94d 100644 --- a/extensions/ide/vscode/devbox/src/utils/file.ts +++ b/extensions/ide/vscode/devbox/src/utils/file.ts @@ -6,10 +6,18 @@ import { execa } from 'execa' // File access permission modification export const ensureFileAccessPermission = async (path: string) => { if (os.platform() === 'win32') { - const username = os.userInfo().username - await execa('icacls', [path, '/inheritance:r']) - await execa('icacls', [path, '/grant:r', `${username}:F`]) - await execa('icacls', [path, '/remove:g', 'everyone']) + try { + const username = os.userInfo().username + if (!username) { + throw new Error('can not get username') + } + await execa('icacls', [path, '/inheritance:r']) + await execa('icacls', [path, '/grant:r', `${username}:F`]) + await execa('icacls', [path, '/remove:g', 'everyone']) + } catch (error) { + console.error('set file access permission failed:', error) + throw new Error(`set file access permission failed: ${error.message}`) + } } else { await execa('chmod', ['600', path]) }