Skip to content

Commit 06ee79d

Browse files
author
Maël Nison
committed
wip
1 parent 93fc256 commit 06ee79d

File tree

3 files changed

+21
-20
lines changed

3 files changed

+21
-20
lines changed

__tests__/integration.js

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -77,38 +77,30 @@ test('cache folder fallback', async () => {
7777
const cwd = await makeTemp();
7878
const cacheFolder = path.join(cwd, '.cache');
7979

80-
await fs.mkdirp(cacheFolder);
81-
8280
const command = path.resolve(__dirname, '../bin/yarn');
8381
const args = ['--preferred-cache-folder', cacheFolder];
8482

8583
const options = {cwd};
8684

87-
{
85+
function runCacheDir(): Promise<Array<Buffer>> {
8886
const {stderr, stdout} = execa(command, ['cache', 'dir'].concat(args), options);
8987

9088
const stdoutPromise = misc.consumeStream(stdout);
9189
const stderrPromise = misc.consumeStream(stderr);
9290

93-
const [stdoutOutput, stderrOutput] = await Promise.all([stdoutPromise, stderrPromise]);
94-
95-
expect(stdoutOutput.toString().trim()).toEqual(path.join(cacheFolder, `v${constants.CACHE_VERSION}`));
96-
expect(stderrOutput.toString()).not.toMatch(/Skipping preferred cache folder/);
91+
return Promise.all([stdoutPromise, stderrPromise]);
9792
}
9893

99-
await fs.chmod(cacheFolder, 0o000);
94+
const [stdoutOutput, stderrOutput] = await runCacheDir();
10095

101-
{
102-
const {stderr, stdout} = execa(command, ['cache', 'dir'].concat(args), options);
96+
expect(stdoutOutput.toString().trim()).toEqual(path.join(cacheFolder, `v${constants.CACHE_VERSION}`));
97+
expect(stderrOutput.toString()).not.toMatch(/Skipping preferred cache folder/);
10398

104-
const stdoutPromise = misc.consumeStream(stdout);
105-
const stderrPromise = misc.consumeStream(stderr);
99+
await fs.unlink(cacheFolder);
100+
await fs.writeFile(cacheFolder, `not a directory`);
106101

107-
const [stdoutOutput, stderrOutput] = await Promise.all([stdoutPromise, stderrPromise]);
102+
const [stdoutOutput2, stderrOutput2] = await runCacheDir();
108103

109-
expect(stdoutOutput.toString().trim()).toEqual(
110-
path.join(constants.PREFERRED_MODULE_CACHE_DIRECTORIES[0], `v${constants.CACHE_VERSION}`),
111-
);
112-
expect(stderrOutput.toString()).toMatch(/Skipping preferred cache folder/);
113-
}
104+
expect(stdoutOutput2.toString().trim()).toEqual(path.join(constants.PREFERRED_MODULE_CACHE_DIRECTORIES[0], `v${constants.CACHE_VERSION}`));
105+
expect(stderrOutput2.toString()).toMatch(/Skipping preferred cache folder/);
114106
});

src/config.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,10 +291,18 @@ export default class Config {
291291
const tentativeCacheFolder = String(preferredCacheFolders[t]);
292292

293293
try {
294+
294295
await fs.mkdirp(tentativeCacheFolder);
295-
// eslint-disable-next-line
296-
await fs.access(tentativeCacheFolder, fs.constants.R_OK | fs.constants.W_OK | fs.constants.X_OK);
296+
297+
const testFile = path.join(tentativeCacheFolder, 'testfile');
298+
299+
// fs.access is not enough, because the cache folder could actually be a file.
300+
await fs.writeFile(testFile, 'content');
301+
await fs.readFile(testFile);
302+
await fs.unlink(testFile);
303+
297304
cacheRootFolder = tentativeCacheFolder;
305+
298306
} catch (error) {
299307
this.reporter.warn(this.reporter.lang('cacheFolderSkipped', tentativeCacheFolder));
300308
}

src/reporters/base-reporter.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ export default class BaseReporter {
195195
success(message: string) {}
196196

197197
// a simple log message
198+
// TODO: rethink the {force} parameter. In the meantime, please don't use it (cf comments in #4143).
198199
log(message: string, {force = false}: {force?: boolean} = {}) {}
199200

200201
// a shell command has been executed

0 commit comments

Comments
 (0)