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

cli: treat /dev/null as non-existing file #135645

Merged
merged 2 commits into from Oct 23, 2021
Merged
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
30 changes: 23 additions & 7 deletions src/vs/platform/windows/electron-main/windowsMainService.ts
Expand Up @@ -17,7 +17,7 @@ import { Disposable, DisposableStore } from 'vs/base/common/lifecycle';
import { Schemas } from 'vs/base/common/network';
import { basename, join, normalize, posix } from 'vs/base/common/path';
import { getMarks, mark } from 'vs/base/common/performance';
import { IProcessEnvironment, isMacintosh } from 'vs/base/common/platform';
import { IProcessEnvironment, isMacintosh, isWindows } from 'vs/base/common/platform';
import { cwd } from 'vs/base/common/process';
import { extUriBiasedIgnorePathCase, normalizePath, originalFSPath, removeTrailingPathSeparator } from 'vs/base/common/resources';
import { equalsIgnoreCase } from 'vs/base/common/strings';
Expand Down Expand Up @@ -974,6 +974,8 @@ export class WindowsMainService extends Disposable implements IWindowsMainServic

try {
const pathStat = statSync(path);

// File
if (pathStat.isFile()) {

// Workspace (unless disabled via flag)
Expand All @@ -991,19 +993,30 @@ export class WindowsMainService extends Disposable implements IWindowsMainServic
}
}

// File
return {
fileUri: URI.file(path),
selection: lineNumber ? { startLineNumber: lineNumber, startColumn: columnNumber || 1 } : undefined,
exists: true
};
}

// Folder (we check for isDirectory() because e.g. paths like /dev/null
// are neither file nor folder but some external tools might pass them
// over to us)
// Folder
else if (pathStat.isDirectory()) {
return { workspace: getSingleFolderWorkspaceIdentifier(URI.file(path), pathStat), exists: true };
return {
workspace: getSingleFolderWorkspaceIdentifier(URI.file(path), pathStat),
exists: true
};
}

// Special device: in POSIX environments, we may get /dev/null passed
// in (for example git uses it to signal one side of a diff does not
// exist). In that special case, treat it like a file to support this
// scenario ()
else if (!isWindows && path === '/dev/null') {
return {
fileUri: URI.file(path),
exists: true
};
}
} catch (error) {
const fileUri = URI.file(path);
Expand All @@ -1013,7 +1026,10 @@ export class WindowsMainService extends Disposable implements IWindowsMainServic

// assume this is a file that does not yet exist
if (options.ignoreFileNotFound) {
return { fileUri, exists: false };
return {
fileUri,
exists: false
};
}
}

Expand Down