Skip to content

Commit

Permalink
Fix read permission error on ignore files search (#259)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-goudry committed Feb 11, 2024
1 parent bd76374 commit 3a28601
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
Empty file.
21 changes: 11 additions & 10 deletions ignore.js
Expand Up @@ -8,13 +8,13 @@ import slash from 'slash';
import {toPath} from 'unicorn-magic';
import {isNegativePattern} from './utilities.js';

const defaultIgnoredDirectories = [
'**/node_modules',
'**/flow-typed',
'**/coverage',
'**/.git',
];
const ignoreFilesGlobOptions = {
ignore: [
'**/node_modules',
'**/flow-typed',
'**/coverage',
'**/.git',
],
absolute: true,
dot: true,
};
Expand Down Expand Up @@ -62,12 +62,13 @@ const normalizeOptions = (options = {}) => ({
cwd: toPath(options.cwd) ?? process.cwd(),
suppressErrors: Boolean(options.suppressErrors),
deep: typeof options.deep === 'number' ? options.deep : Number.POSITIVE_INFINITY,
ignore: [...options.ignore ?? [], ...defaultIgnoredDirectories],
});

export const isIgnoredByIgnoreFiles = async (patterns, options) => {
const {cwd, suppressErrors, deep} = normalizeOptions(options);
const {cwd, suppressErrors, deep, ignore} = normalizeOptions(options);

const paths = await fastGlob(patterns, {cwd, suppressErrors, deep, ...ignoreFilesGlobOptions});
const paths = await fastGlob(patterns, {cwd, suppressErrors, deep, ignore, ...ignoreFilesGlobOptions});

const files = await Promise.all(
paths.map(async filePath => ({
Expand All @@ -80,9 +81,9 @@ export const isIgnoredByIgnoreFiles = async (patterns, options) => {
};

export const isIgnoredByIgnoreFilesSync = (patterns, options) => {
const {cwd, suppressErrors, deep} = normalizeOptions(options);
const {cwd, suppressErrors, deep, ignore} = normalizeOptions(options);

const paths = fastGlob.sync(patterns, {cwd, suppressErrors, deep, ...ignoreFilesGlobOptions});
const paths = fastGlob.sync(patterns, {cwd, suppressErrors, deep, ignore, ...ignoreFilesGlobOptions});

const files = paths.map(filePath => ({
filePath,
Expand Down
19 changes: 19 additions & 0 deletions tests/ignore.js
@@ -1,3 +1,4 @@
import {chmod} from 'node:fs/promises';
import path from 'node:path';
import test from 'ava';
import slash from 'slash';
Expand Down Expand Up @@ -186,3 +187,21 @@ test('custom ignore files', async t => {
],
);
});

test.serial('bad permissions', async t => {
const cwd = path.join(PROJECT_ROOT, 'fixtures/bad-permissions');
const noReadDirectory = path.join(cwd, 'noread');

await chmod(noReadDirectory, 0o000);

await t.notThrowsAsync(
runIsIgnoredByIgnoreFiles(
t,
'**/*',
{cwd, ignore: ['noread']},
() => {},
),
);

t.teardown(() => chmod(noReadDirectory, 0o755));
});

0 comments on commit 3a28601

Please sign in to comment.