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

Allow symlinks in MountFS #5474

Closed
wants to merge 2 commits into from
Closed
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
37 changes: 37 additions & 0 deletions .yarn/versions/757578fa.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
releases:
"@yarnpkg/builder": patch
"@yarnpkg/cli": patch
"@yarnpkg/core": patch
"@yarnpkg/doctor": patch
"@yarnpkg/extensions": patch
"@yarnpkg/fslib": minor
"@yarnpkg/libzip": patch
"@yarnpkg/nm": patch
"@yarnpkg/plugin-compat": patch
"@yarnpkg/plugin-constraints": patch
"@yarnpkg/plugin-dlx": patch
"@yarnpkg/plugin-essentials": patch
"@yarnpkg/plugin-exec": patch
"@yarnpkg/plugin-file": patch
"@yarnpkg/plugin-git": patch
"@yarnpkg/plugin-github": patch
"@yarnpkg/plugin-http": patch
"@yarnpkg/plugin-init": patch
"@yarnpkg/plugin-interactive-tools": patch
"@yarnpkg/plugin-link": patch
"@yarnpkg/plugin-nm": patch
"@yarnpkg/plugin-npm": patch
"@yarnpkg/plugin-npm-cli": patch
"@yarnpkg/plugin-pack": patch
"@yarnpkg/plugin-patch": patch
"@yarnpkg/plugin-pnp": patch
"@yarnpkg/plugin-pnpm": patch
"@yarnpkg/plugin-stage": patch
"@yarnpkg/plugin-typescript": patch
"@yarnpkg/plugin-version": patch
"@yarnpkg/plugin-workspace-tools": patch
"@yarnpkg/pnp": patch
"@yarnpkg/pnpify": patch
"@yarnpkg/sdks": patch
"@yarnpkg/shell": patch
vscode-zipfs: patch
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,33 @@ describe(`Commands`, () => {
}),
);

tests.testIf(
() => process.platform !== `win32`,
`it should install from zips that are symlinks`,
makeTemporaryEnv({
dependencies: {
[`no-deps`]: `1.0.0`,
},
}, async ({path, run, source}) => {
await run(`install`);

const allFiles = await xfs.readdirPromise(ppath.join(path, `.yarn/cache`));
const zipFiles = allFiles.filter(file => file.endsWith(`.zip`));

await xfs.mkdirPromise(ppath.join(path, `store`));
for (const filename of zipFiles) {
const zipFile = ppath.join(path, `.yarn/cache`, filename);
const storePath = ppath.join(path, `store`, filename);
await xfs.movePromise(zipFile, storePath);
await xfs.symlinkPromise(storePath, zipFile);
}

await xfs.removePromise(ppath.join(path, Filename.pnpCjs));

await run(`install`, `--immutable`);
}),
);

test(
`it should refuse to create a lockfile when using --immutable`,
makeTemporaryEnv({
Expand Down
27 changes: 27 additions & 0 deletions packages/acceptance-tests/pkg-tests-specs/sources/pnp.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2253,4 +2253,31 @@ describe(`Plug'n'Play`, () => {
});
}),
);

testIf(
() => process.platform !== `win32`,
`it can resolve files from zips that are symlinks`,
makeTemporaryEnv({
dependencies: {
[`no-deps`]: `1.0.0`,
},
}, async ({path, run, source}) => {
await run(`install`);

const allFiles = await xfs.readdirPromise(ppath.join(path, `.yarn/cache`));
const zipFiles = allFiles.filter(file => file.endsWith(`.zip`));

await xfs.mkdirPromise(ppath.join(path, `store`));
for (const filename of zipFiles) {
const zipFile = ppath.join(path, `.yarn/cache`, filename);
const storePath = ppath.join(path, `store`, filename);
await xfs.movePromise(zipFile, storePath);
await xfs.symlinkPromise(storePath, zipFile);
}

await expect(
source(`require('no-deps')`),
).resolves.toEqual({name: `no-deps`, version: `1.0.0`});
}),
);
});
2 changes: 1 addition & 1 deletion packages/yarnpkg-fslib/sources/MountFS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1013,7 +1013,7 @@ export class MountFS<MountedFS extends MountableFS> extends BasePortableFakeFS {
continue;

try {
if (this.typeCheck !== null && (this.baseFs.lstatSync(filePath).mode & constants.S_IFMT) !== this.typeCheck) {
if (this.typeCheck !== null && (this.baseFs.statSync(filePath).mode & constants.S_IFMT) !== this.typeCheck) {
this.notMount.add(filePath);
continue;
}
Expand Down
13 changes: 13 additions & 0 deletions packages/yarnpkg-libzip/tests/ZipOpenFS.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,15 @@ export const ZIP_DIR3 = ppath.join(
npath.toPortablePath(__dirname),
`fixtures/foo.hiddenzip` as Filename,
);
export const ZIP_DIR4 = ppath.join(
npath.toPortablePath(__dirname),
`fixtures/symlink.zip` as Filename,
);

export const ZIP_FILE1 = ppath.join(ZIP_DIR1, `foo.txt`);
export const ZIP_FILE2 = ppath.join(ZIP_DIR2, `foo.txt`);
export const ZIP_FILE3 = ppath.join(ZIP_DIR3, `foo.txt`);
export const ZIP_FILE4 = ppath.join(ZIP_DIR4, `foo.txt`);

afterEach(() => {
jest.useRealTimers();
Expand Down Expand Up @@ -81,6 +86,14 @@ describe(`ZipOpenFS`, () => {
fs.discardAndClose();
});

it(`can read from a zip file that's a symlink`, () => {
const fs = new ZipOpenFS();

expect(fs.readFileSync(ZIP_FILE4, `utf8`)).toEqual(`foo\n`);

fs.discardAndClose();
});

it(`doesn't close a ZipFS instance with open handles`, () => {
const fs = new ZipOpenFS({maxOpenFiles: 1});

Expand Down
Binary file not shown.
1 change: 1 addition & 0 deletions packages/yarnpkg-libzip/tests/fixtures/symlink.zip
Loading