mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-26 19:44:25 +01:00
Pass exact path matches to find (#12743)
This commit is contained in:
@@ -256,16 +256,16 @@ export class FileWalker {
|
||||
*/
|
||||
public spawnFindCmd(rootFolder: string, excludePattern: glob.ParsedExpression) {
|
||||
const basenames = glob.getBasenameTerms(excludePattern);
|
||||
const pathEnds = glob.getPathEndTerms(excludePattern);
|
||||
const paths = glob.getPathTerms(excludePattern);
|
||||
let args = ['-L', '.'];
|
||||
if (basenames.length || pathEnds.length) {
|
||||
if (basenames.length || paths.length) {
|
||||
args.push('-not', '(', '(');
|
||||
for (const basename of basenames) {
|
||||
args.push('-name', FileWalker.escapeGlobSpecials(basename));
|
||||
args.push('-name', basename);
|
||||
args.push('-o');
|
||||
}
|
||||
for (const pathEnd of pathEnds) {
|
||||
args.push('-path', '*' + FileWalker.escapeGlobSpecials(pathEnd));
|
||||
for (const path of paths) {
|
||||
args.push('-path', path);
|
||||
args.push('-o');
|
||||
}
|
||||
args.pop();
|
||||
@@ -275,12 +275,6 @@ export class FileWalker {
|
||||
return childProcess.spawn('find', args, { cwd: rootFolder });
|
||||
}
|
||||
|
||||
private static GLOB_SPECIALS = /[*?\[\]\\]/g;
|
||||
private static ESCAPE_CHAR = '\\$&';
|
||||
private static escapeGlobSpecials(string) {
|
||||
return string.replace(this.GLOB_SPECIALS, this.ESCAPE_CHAR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Public for testing.
|
||||
*/
|
||||
|
||||
@@ -478,7 +478,7 @@ suite('Search', () => {
|
||||
});
|
||||
});
|
||||
|
||||
test('Find: exclude folder path', function (done: () => void) {
|
||||
test('Find: exclude folder path suffix', function (done: () => void) {
|
||||
if (platform.isWindows) {
|
||||
done();
|
||||
return;
|
||||
@@ -504,7 +504,7 @@ suite('Search', () => {
|
||||
});
|
||||
});
|
||||
|
||||
test('Find: exclude subfolder path', function (done: () => void) {
|
||||
test('Find: exclude subfolder path suffix', function (done: () => void) {
|
||||
if (platform.isWindows) {
|
||||
done();
|
||||
return;
|
||||
@@ -530,6 +530,32 @@ suite('Search', () => {
|
||||
});
|
||||
});
|
||||
|
||||
test('Find: exclude folder path', function (done: () => void) {
|
||||
if (platform.isWindows) {
|
||||
done();
|
||||
return;
|
||||
}
|
||||
|
||||
const walker = new FileWalker({ rootFolders: rootfolders() });
|
||||
const file0 = './examples/company.js';
|
||||
const file1 = './examples/subfolder/subfile.txt';
|
||||
|
||||
const cmd1 = walker.spawnFindCmd(rootfolders()[0], glob.parse({ 'examples/something': true }));
|
||||
walker.readStdout(cmd1, 'utf8', (err1, stdout1) => {
|
||||
assert.equal(err1, null);
|
||||
assert.notStrictEqual(stdout1.split('\n').indexOf(file0), -1, stdout1);
|
||||
assert.notStrictEqual(stdout1.split('\n').indexOf(file1), -1, stdout1);
|
||||
|
||||
const cmd2 = walker.spawnFindCmd(rootfolders()[0], glob.parse({ 'examples/subfolder': true }));
|
||||
walker.readStdout(cmd2, 'utf8', (err2, stdout2) => {
|
||||
assert.equal(err2, null);
|
||||
assert.notStrictEqual(stdout1.split('\n').indexOf(file0), -1, stdout1);
|
||||
assert.strictEqual(stdout2.split('\n').indexOf(file1), -1, stdout2);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test('Find: exclude combination of paths', function (done: () => void) {
|
||||
if (platform.isWindows) {
|
||||
done();
|
||||
|
||||
Reference in New Issue
Block a user