Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix read permission error on ignore files search #259

Merged
merged 2 commits into from
Feb 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
21 changes: 11 additions & 10 deletions ignore.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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));
});