Skip to content

Commit

Permalink
cli: treat /dev/null as non-existing file (#135645)
Browse files Browse the repository at this point in the history
* cli: treat /dev/null as non-existing file

* 💄

Co-authored-by: Benjamin Pasero <benjamin.pasero@microsoft.com>
  • Loading branch information
aeschli and bpasero committed Oct 23, 2021
1 parent 5e10a96 commit 6c0929c
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions src/vs/platform/windows/electron-main/windowsMainService.ts
Original file line number Diff line number Diff line change
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

0 comments on commit 6c0929c

Please sign in to comment.