Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

debt - ensure file scheme when using .fsPath #191960

Merged
merged 1 commit into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/vs/code/electron-main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,10 @@ class CodeMain {
Promise.all<string | undefined>([
environmentMainService.extensionsPath,
environmentMainService.codeCachePath,
environmentMainService.logsHome.fsPath,
userDataProfilesMainService.defaultProfile.globalStorageHome.fsPath,
environmentMainService.workspaceStorageHome.fsPath,
environmentMainService.localHistoryHome.fsPath,
environmentMainService.logsHome.with({ scheme: Schemas.file }).fsPath,
userDataProfilesMainService.defaultProfile.globalStorageHome.with({ scheme: Schemas.file }).fsPath,
environmentMainService.workspaceStorageHome.with({ scheme: Schemas.file }).fsPath,
environmentMainService.localHistoryHome.with({ scheme: Schemas.file }).fsPath,
environmentMainService.backupHome
].map(path => path ? FSPromises.mkdir(path, { recursive: true }) : undefined)),

Expand Down
2 changes: 1 addition & 1 deletion src/vs/code/node/cliProcessMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class CliMain extends Disposable {

// Init folders
await Promise.all([
environmentService.appSettingsHome.fsPath,
environmentService.appSettingsHome.with({ scheme: Schemas.file }).fsPath,
environmentService.extensionsPath
].map(path => path ? Promises.mkdir(path, { recursive: true }) : undefined));

Expand Down
11 changes: 6 additions & 5 deletions src/vs/code/node/sharedProcess/contrib/logsDataCleaner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
import { RunOnceScheduler } from 'vs/base/common/async';
import { onUnexpectedError } from 'vs/base/common/errors';
import { Disposable } from 'vs/base/common/lifecycle';
import { basename, dirname, joinPath } from 'vs/base/common/resources';
import { Schemas } from 'vs/base/common/network';
import { join } from 'vs/base/common/path';
import { basename, dirname } from 'vs/base/common/resources';
import { Promises } from 'vs/base/node/pfs';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { ILogService } from 'vs/platform/log/common/log';
Expand All @@ -30,9 +32,8 @@ export class LogsDataCleaner extends Disposable {

try {
const currentLog = basename(this.environmentService.logsHome);
const logsRoot = dirname(this.environmentService.logsHome);

const logFiles = await Promises.readdir(logsRoot.fsPath);
const logsRoot = dirname(this.environmentService.logsHome.with({ scheme: Schemas.file })).fsPath;
const logFiles = await Promises.readdir(logsRoot);

const allSessions = logFiles.filter(logFile => /^\d{8}T\d{6}$/.test(logFile));
const oldSessions = allSessions.sort().filter(session => session !== currentLog);
Expand All @@ -41,7 +42,7 @@ export class LogsDataCleaner extends Disposable {
if (sessionsToDelete.length > 0) {
this.logService.trace(`[logs cleanup]: Removing log folders '${sessionsToDelete.join(', ')}'`);

await Promise.all(sessionsToDelete.map(sessionToDelete => Promises.rm(joinPath(logsRoot, sessionToDelete).fsPath)));
await Promise.all(sessionsToDelete.map(sessionToDelete => Promises.rm(join(logsRoot, sessionToDelete))));
}
} catch (error) {
onUnexpectedError(error);
Expand Down
6 changes: 4 additions & 2 deletions src/vs/code/node/sharedProcess/contrib/storageDataCleaner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { EXTENSION_DEVELOPMENT_EMPTY_WINDOW_WORKSPACE } from 'vs/platform/worksp
import { NON_EMPTY_WORKSPACE_ID_LENGTH } from 'vs/platform/workspaces/node/workspaces';
import { INativeHostService } from 'vs/platform/native/common/native';
import { IMainProcessService } from 'vs/platform/ipc/common/mainProcessService';
import { Schemas } from 'vs/base/common/network';

export class UnusedWorkspaceStorageDataCleaner extends Disposable {

Expand All @@ -36,11 +37,12 @@ export class UnusedWorkspaceStorageDataCleaner extends Disposable {
this.logService.trace('[storage cleanup]: Starting to clean up workspace storage folders for unused empty workspaces.');

try {
const workspaceStorageFolders = await Promises.readdir(this.environmentService.workspaceStorageHome.fsPath);
const workspaceStorageHome = this.environmentService.workspaceStorageHome.with({ scheme: Schemas.file }).fsPath;
const workspaceStorageFolders = await Promises.readdir(workspaceStorageHome);
const storageClient = new StorageClient(this.mainProcessService.getChannel('storage'));

await Promise.all(workspaceStorageFolders.map(async workspaceStorageFolder => {
const workspaceStoragePath = join(this.environmentService.workspaceStorageHome.fsPath, workspaceStorageFolder);
const workspaceStoragePath = join(workspaceStorageHome, workspaceStorageFolder);

if (workspaceStorageFolder.length === NON_EMPTY_WORKSPACE_ID_LENGTH) {
return; // keep workspace storage for folders/workspaces that can be accessed still
Expand Down
4 changes: 2 additions & 2 deletions src/vs/platform/protocol/electron-main/protocolMainService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ export class ProtocolMainService extends Disposable implements IProtocolMainServ
// - storage : all files in global and workspace storage (https://github.com/microsoft/vscode/issues/116735)
this.addValidFileRoot(environmentService.appRoot);
this.addValidFileRoot(environmentService.extensionsPath);
this.addValidFileRoot(userDataProfilesService.defaultProfile.globalStorageHome.fsPath);
this.addValidFileRoot(environmentService.workspaceStorageHome.fsPath);
this.addValidFileRoot(userDataProfilesService.defaultProfile.globalStorageHome.with({ scheme: Schemas.file }).fsPath);
this.addValidFileRoot(environmentService.workspaceStorageHome.with({ scheme: Schemas.file }).fsPath);

// Handle protocols
this.handleProtocols();
Expand Down
7 changes: 4 additions & 3 deletions src/vs/platform/storage/common/storageService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import { Promises } from 'vs/base/common/async';
import { DisposableStore } from 'vs/base/common/lifecycle';
import { Schemas } from 'vs/base/common/network';
import { joinPath } from 'vs/base/common/resources';
import { IStorage, Storage } from 'vs/base/parts/storage/common/storage';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
Expand Down Expand Up @@ -117,11 +118,11 @@ export class RemoteStorageService extends AbstractStorageService {
protected getLogDetails(scope: StorageScope): string | undefined {
switch (scope) {
case StorageScope.APPLICATION:
return this.applicationStorageProfile.globalStorageHome.fsPath;
return this.applicationStorageProfile.globalStorageHome.with({ scheme: Schemas.file }).fsPath;
case StorageScope.PROFILE:
return this.profileStorageProfile?.globalStorageHome.fsPath;
return this.profileStorageProfile?.globalStorageHome.with({ scheme: Schemas.file }).fsPath;
default:
return this.workspaceStorageId ? `${joinPath(this.environmentService.workspaceStorageHome, this.workspaceStorageId, 'state.vscdb').fsPath}` : undefined;
return this.workspaceStorageId ? `${joinPath(this.environmentService.workspaceStorageHome, this.workspaceStorageId, 'state.vscdb').with({ scheme: Schemas.file }).fsPath}` : undefined;
}
}

Expand Down
7 changes: 4 additions & 3 deletions src/vs/platform/storage/electron-main/storageMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { IS_NEW_KEY } from 'vs/platform/storage/common/storage';
import { IUserDataProfile, IUserDataProfilesService } from 'vs/platform/userDataProfile/common/userDataProfile';
import { currentSessionDateStorageKey, firstSessionDateStorageKey, lastSessionDateStorageKey } from 'vs/platform/telemetry/common/telemetry';
import { isSingleFolderWorkspaceIdentifier, isWorkspaceIdentifier, IAnyWorkspaceIdentifier } from 'vs/platform/workspace/common/workspace';
import { Schemas } from 'vs/base/common/network';

export interface IStorageMainOptions {

Expand Down Expand Up @@ -275,7 +276,7 @@ class BaseProfileAwareStorageMain extends BaseStorageMain {

get path(): string | undefined {
if (!this.options.useInMemoryStorage) {
return join(this.profile.globalStorageHome.fsPath, BaseProfileAwareStorageMain.STORAGE_NAME);
return join(this.profile.globalStorageHome.with({ scheme: Schemas.file }).fsPath, BaseProfileAwareStorageMain.STORAGE_NAME);
}

return undefined;
Expand Down Expand Up @@ -352,7 +353,7 @@ export class WorkspaceStorageMain extends BaseStorageMain {

get path(): string | undefined {
if (!this.options.useInMemoryStorage) {
return join(this.environmentService.workspaceStorageHome.fsPath, this.workspace.id, WorkspaceStorageMain.WORKSPACE_STORAGE_NAME);
return join(this.environmentService.workspaceStorageHome.with({ scheme: Schemas.file }).fsPath, this.workspace.id, WorkspaceStorageMain.WORKSPACE_STORAGE_NAME);
}

return undefined;
Expand Down Expand Up @@ -384,7 +385,7 @@ export class WorkspaceStorageMain extends BaseStorageMain {
}

// Otherwise, ensure the storage folder exists on disk
const workspaceStorageFolderPath = join(this.environmentService.workspaceStorageHome.fsPath, this.workspace.id);
const workspaceStorageFolderPath = join(this.environmentService.workspaceStorageHome.with({ scheme: Schemas.file }).fsPath, this.workspace.id);
const workspaceStorageDatabasePath = join(workspaceStorageFolderPath, WorkspaceStorageMain.WORKSPACE_STORAGE_NAME);

const storageExists = await Promises.exists(workspaceStorageFolderPath);
Expand Down
3 changes: 2 additions & 1 deletion src/vs/platform/storage/electron-main/storageMainService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { IUserDataProfile, IUserDataProfilesService } from 'vs/platform/userData
import { IUserDataProfilesMainService } from 'vs/platform/userDataProfile/electron-main/userDataProfile';
import { IAnyWorkspaceIdentifier } from 'vs/platform/workspace/common/workspace';
import { IUriIdentityService } from 'vs/platform/uriIdentity/common/uriIdentity';
import { Schemas } from 'vs/base/common/network';

//#region Storage Main Service (intent: make application, profile and workspace storage accessible to windows from main process)

Expand Down Expand Up @@ -359,7 +360,7 @@ export class ApplicationStorageMainService extends AbstractStorageService implem

protected getLogDetails(scope: StorageScope): string | undefined {
if (scope === StorageScope.APPLICATION) {
return this.userDataProfilesService.defaultProfile.globalStorageHome.fsPath;
return this.userDataProfilesService.defaultProfile.globalStorageHome.with({ scheme: Schemas.file }).fsPath;
}

return undefined; // any other scope is unsupported from main process
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { Disposable, DisposableStore, toDisposable } from 'vs/base/common/lifecy
import { Emitter } from 'vs/base/common/event';
import { deepClone } from 'vs/base/common/objects';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { Schemas } from 'vs/base/common/network';

export class ElectronPtyHostStarter extends Disposable implements IPtyHostStarter {

Expand Down Expand Up @@ -58,7 +59,7 @@ export class ElectronPtyHostStarter extends Disposable implements IPtyHostStarte
type: 'ptyHost',
entryPoint: 'vs/platform/terminal/node/ptyHostMain',
execArgv,
args: ['--logsPath', this._environmentMainService.logsHome.fsPath],
args: ['--logsPath', this._environmentMainService.logsHome.with({ scheme: Schemas.file }).fsPath],
env: this._createPtyHostConfiguration()
});

Expand Down
4 changes: 2 additions & 2 deletions src/vs/platform/terminal/node/nodePtyHostStarter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/

import { Disposable, DisposableStore } from 'vs/base/common/lifecycle';
import { FileAccess } from 'vs/base/common/network';
import { FileAccess, Schemas } from 'vs/base/common/network';
import { Client, IIPCOptions } from 'vs/base/parts/ipc/node/ipc.cp';
import { IEnvironmentService, INativeEnvironmentService } from 'vs/platform/environment/common/environment';
import { parsePtyHostDebugPort } from 'vs/platform/environment/node/environmentService';
Expand All @@ -22,7 +22,7 @@ export class NodePtyHostStarter extends Disposable implements IPtyHostStarter {
start(): IPtyHostConnection {
const opts: IIPCOptions = {
serverName: 'Pty Host',
args: ['--type=ptyHost', '--logsPath', this._environmentService.logsHome.fsPath],
args: ['--type=ptyHost', '--logsPath', this._environmentService.logsHome.with({ scheme: Schemas.file }).fsPath],
env: {
VSCODE_AMD_ENTRYPOINT: 'vs/platform/terminal/node/ptyHostMain',
VSCODE_PIPE_LOGGING: 'true',
Expand Down
6 changes: 3 additions & 3 deletions src/vs/platform/windows/electron-main/windowsMainService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1401,8 +1401,8 @@ export class WindowsMainService extends Disposable implements IWindowsMainServic
profile: defaultProfile
},

homeDir: this.environmentMainService.userHome.fsPath,
tmpDir: this.environmentMainService.tmpDir.fsPath,
homeDir: this.environmentMainService.userHome.with({ scheme: Schemas.file }).fsPath,
tmpDir: this.environmentMainService.tmpDir.with({ scheme: Schemas.file }).fsPath,
userDataDir: this.environmentMainService.userDataPath,

remoteAuthority: options.remoteAuthority,
Expand All @@ -1419,7 +1419,7 @@ export class WindowsMainService extends Disposable implements IWindowsMainServic
window: [],
global: this.loggerService.getRegisteredLoggers()
},
logsPath: this.environmentMainService.logsHome.fsPath,
logsPath: this.environmentMainService.logsHome.with({ scheme: Schemas.file }).fsPath,

product,
isInitialStartup: options.initialStartup,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export class WorkspacesManagementMainService extends Disposable implements IWork

// Resolve untitled workspaces
try {
const untitledWorkspacePaths = (await Promises.readdir(this.untitledWorkspacesHome.fsPath)).map(folder => joinPath(this.untitledWorkspacesHome, folder, UNTITLED_WORKSPACE_NAME));
const untitledWorkspacePaths = (await Promises.readdir(this.untitledWorkspacesHome.with({ scheme: Schemas.file }).fsPath)).map(folder => joinPath(this.untitledWorkspacesHome, folder, UNTITLED_WORKSPACE_NAME));//
for (const untitledWorkspacePath of untitledWorkspacePaths) {
const workspace = getWorkspaceIdentifier(untitledWorkspacePath);
const resolvedWorkspace = await this.resolveLocalWorkspace(untitledWorkspacePath);
Expand Down Expand Up @@ -227,7 +227,7 @@ export class WorkspacesManagementMainService extends Disposable implements IWork
await Promises.rm(dirname(configPath));

// Mark Workspace Storage to be deleted
const workspaceStoragePath = join(this.environmentMainService.workspaceStorageHome.fsPath, workspace.id);
const workspaceStoragePath = join(this.environmentMainService.workspaceStorageHome.with({ scheme: Schemas.file }).fsPath, workspace.id);
if (await Promises.exists(workspaceStoragePath)) {
await Promises.writeFile(join(workspaceStoragePath, 'obsolete'), '');
}
Expand Down
2 changes: 1 addition & 1 deletion src/vs/server/node/serverServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export async function setupServerServices(connectionToken: ServerConnectionToken
const logger = loggerService.createLogger('remoteagent', { name: localize('remoteExtensionLog', "Server") });
const logService = new LogService(logger, [new ServerLogger(getLogLevel(environmentService))]);
services.set(ILogService, logService);
setTimeout(() => cleanupOlderLogs(environmentService.logsHome.fsPath).then(null, err => logService.error(err)), 10000);
setTimeout(() => cleanupOlderLogs(environmentService.logsHome.with({ scheme: Schemas.file }).fsPath).then(null, err => logService.error(err)), 10000);
logService.onDidChangeLogLevel(logLevel => log(logService, logLevel, `Log level changed to ${LogLevelToString(logService.getLevel())}`));

logService.trace(`Remote configuration data at ${REMOTE_DATA_FOLDER}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function revealResourcesInOS(resources: URI[], nativeHostService: INative
if (resources.length) {
sequence(resources.map(r => async () => {
if (r.scheme === Schemas.file || r.scheme === Schemas.vscodeUserData) {
nativeHostService.showItemInFolder(r.fsPath);
nativeHostService.showItemInFolder(r.with({ scheme: Schemas.file }).fsPath);
}
}));
} else if (workspaceContextService.getWorkspace().folders.length) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ registerAction2(class extends Action2 {

const { entry } = await findLocalHistoryEntry(workingCopyHistoryService, item);
if (entry) {
await nativeHostService.showItemInFolder(entry.location.fsPath);
await nativeHostService.showItemInFolder(entry.location.with({ scheme: Schemas.file }).fsPath);
}
}
});
Expand Down
5 changes: 3 additions & 2 deletions src/vs/workbench/contrib/logs/electron-sandbox/logsActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { INativeHostService } from 'vs/platform/native/common/native';
import { INativeWorkbenchEnvironmentService } from 'vs/workbench/services/environment/electron-sandbox/environmentService';
import { IFileService } from 'vs/platform/files/common/files';
import { joinPath } from 'vs/base/common/resources';
import { Schemas } from 'vs/base/common/network';

export class OpenLogsFolderAction extends Action {

Expand All @@ -23,7 +24,7 @@ export class OpenLogsFolderAction extends Action {
}

override run(): Promise<void> {
return this.nativeHostService.showItemInFolder(joinPath(this.environmentService.logsHome, 'main.log').fsPath);
return this.nativeHostService.showItemInFolder(joinPath(this.environmentService.logsHome, 'main.log').with({ scheme: Schemas.file }).fsPath);
}
}

Expand All @@ -43,7 +44,7 @@ export class OpenExtensionLogsFolderAction extends Action {
override async run(): Promise<void> {
const folderStat = await this.fileService.resolve(this.environmentSerice.extHostLogsPath);
if (folderStat.children && folderStat.children[0]) {
return this.nativeHostService.showItemInFolder(folderStat.children[0].resource.fsPath);
return this.nativeHostService.showItemInFolder(folderStat.children[0].resource.with({ scheme: Schemas.file }).fsPath);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { IFileService } from 'vs/platform/files/common/files';
import { INativeHostService } from 'vs/platform/native/common/native';
import { INotificationService } from 'vs/platform/notification/common/notification';
import { CONTEXT_SYNC_STATE, SYNC_TITLE } from 'vs/workbench/services/userDataSync/common/userDataSync';
import { Schemas } from 'vs/base/common/network';

class UserDataSyncServicesContribution implements IWorkbenchContribution {

Expand Down Expand Up @@ -51,7 +52,7 @@ registerAction2(class OpenSyncBackupsFolder extends Action2 {
if (await fileService.exists(syncHome)) {
const folderStat = await fileService.resolve(syncHome);
const item = folderStat.children && folderStat.children[0] ? folderStat.children[0].resource : syncHome;
return nativeHostService.showItemInFolder(item.fsPath);
return nativeHostService.showItemInFolder(item.with({ scheme: Schemas.file }).fsPath);
} else {
notificationService.info(localize('no backups', "Local backups folder does not exist"));
}
Expand Down