Skip to content

Commit

Permalink
Fix file-system access for filled files
Browse files Browse the repository at this point in the history
Virtual files given in `files`, with contents, should not be statted.
  • Loading branch information
wooorm committed Feb 24, 2017
1 parent 8b3b645 commit 0f463a6
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 3 deletions.
7 changes: 5 additions & 2 deletions lib/finder.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,15 @@ function search(input, options, next) {
function statAndIgnore(file, options, callback) {
var ignore = options.ignore;
var fp = resolve(options.cwd, filePath(file));
var expected = 2;
var expected = 1;
var actual = 0;
var stats;
var ignored;

stat(fp, handleStat);
if (!file.contents) {
expected++;
stat(fp, handleStat);
}

ignore.check(fp, handleIgnore);

Expand Down
1 change: 1 addition & 0 deletions test/fixtures/ignore-file/.fooignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
nested/*
!nested/three.txt
not-existing.txt
55 changes: 54 additions & 1 deletion test/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var join = path.join;
var fixtures = join(__dirname, 'fixtures');

test('input', function (t) {
t.plan(16);
t.plan(18);

t.test('should fail without input', function (st) {
var stream = new PassThrough();
Expand Down Expand Up @@ -308,6 +308,59 @@ test('input', function (t) {
});
});

t.test('should not atempt to read files with `contents` (1)', function (st) {
var stderr = spy();
var cwd = join(fixtures, 'ignore-file');
var file = vfile({path: join(cwd, 'not-existing.txt'), contents: 'foo'});

st.plan(3);

engine({
processor: noop,
cwd: cwd,
streamError: stderr.stream,
ignoreName: '.fooignore',
files: [file]
}, function (err, code) {
st.error(err, 'should not fail fatally');
st.equal(code, 1, 'should exit with `1`');

st.equal(
stderr(),
[
'not-existing.txt',
' 1:1 error Cannot process specified file: it’s ignored',
'',
'✖ 1 error',
''
].join('\n'),
'should report'
);
});
});

t.test('should not atempt to read files with `contents` (2)', function (st) {
var stderr = spy();
var cwd = join(fixtures, 'ignore-file');
var file = vfile({path: join(cwd, 'not-existing-2.txt'), contents: 'foo'});

st.plan(1);

engine({
processor: noop,
cwd: cwd,
streamError: stderr.stream,
ignoreName: '.fooignore',
files: [file]
}, function (err, code) {
st.deepEqual(
[err, code, stderr()],
[null, 0, 'not-existing-2.txt: no issues found\n'],
'should report'
);
});
});

t.test('should include given ignored files (#2)', function (st) {
var stderr = spy();

Expand Down

0 comments on commit 0f463a6

Please sign in to comment.