Skip to content

Commit 6c0929c

Browse files
aeschlibpasero
andauthored
cli: treat /dev/null as non-existing file (microsoft#135645)
* cli: treat /dev/null as non-existing file * 💄 Co-authored-by: Benjamin Pasero <[email protected]>
1 parent 5e10a96 commit 6c0929c

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

src/vs/platform/windows/electron-main/windowsMainService.ts

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { Disposable, DisposableStore } from 'vs/base/common/lifecycle';
1717
import { Schemas } from 'vs/base/common/network';
1818
import { basename, join, normalize, posix } from 'vs/base/common/path';
1919
import { getMarks, mark } from 'vs/base/common/performance';
20-
import { IProcessEnvironment, isMacintosh } from 'vs/base/common/platform';
20+
import { IProcessEnvironment, isMacintosh, isWindows } from 'vs/base/common/platform';
2121
import { cwd } from 'vs/base/common/process';
2222
import { extUriBiasedIgnorePathCase, normalizePath, originalFSPath, removeTrailingPathSeparator } from 'vs/base/common/resources';
2323
import { equalsIgnoreCase } from 'vs/base/common/strings';
@@ -974,6 +974,8 @@ export class WindowsMainService extends Disposable implements IWindowsMainServic
974974

975975
try {
976976
const pathStat = statSync(path);
977+
978+
// File
977979
if (pathStat.isFile()) {
978980

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

994-
// File
995996
return {
996997
fileUri: URI.file(path),
997998
selection: lineNumber ? { startLineNumber: lineNumber, startColumn: columnNumber || 1 } : undefined,
998999
exists: true
9991000
};
10001001
}
10011002

1002-
// Folder (we check for isDirectory() because e.g. paths like /dev/null
1003-
// are neither file nor folder but some external tools might pass them
1004-
// over to us)
1003+
// Folder
10051004
else if (pathStat.isDirectory()) {
1006-
return { workspace: getSingleFolderWorkspaceIdentifier(URI.file(path), pathStat), exists: true };
1005+
return {
1006+
workspace: getSingleFolderWorkspaceIdentifier(URI.file(path), pathStat),
1007+
exists: true
1008+
};
1009+
}
1010+
1011+
// Special device: in POSIX environments, we may get /dev/null passed
1012+
// in (for example git uses it to signal one side of a diff does not
1013+
// exist). In that special case, treat it like a file to support this
1014+
// scenario ()
1015+
else if (!isWindows && path === '/dev/null') {
1016+
return {
1017+
fileUri: URI.file(path),
1018+
exists: true
1019+
};
10071020
}
10081021
} catch (error) {
10091022
const fileUri = URI.file(path);
@@ -1013,7 +1026,10 @@ export class WindowsMainService extends Disposable implements IWindowsMainServic
10131026

10141027
// assume this is a file that does not yet exist
10151028
if (options.ignoreFileNotFound) {
1016-
return { fileUri, exists: false };
1029+
return {
1030+
fileUri,
1031+
exists: false
1032+
};
10171033
}
10181034
}
10191035

0 commit comments

Comments
 (0)