Skip to content
Open
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
5 changes: 4 additions & 1 deletion packages/zpm/src/linker/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,9 +469,12 @@ fn link_into_cas(target_path: &Path, data: &[u8], mode: u32, index_root: &Path)
if needs_rewrite {
// Write through the existing path: cross-project hardlinks
// inherit the repair without losing inode identity.
if index_path.fs_exists() {
index_path.fs_set_permissions(Permissions::from_mode(mode_bits | 0o200))?;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rather than checking for existence we should rather tolerate enoent errors (see ok_missing)

}
index_path.fs_write(data)?;
index_path.fs_set_permissions(Permissions::from_mode(mode_bits))?;
set_safe_mtime(&index_path)?;
index_path.fs_set_permissions(Permissions::from_mode(mode_bits))?;
}

ensure_hardlink(target_path, &index_path)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,35 @@
import {Filename, ppath, xfs} from '@yarnpkg/fslib';
import {fs as fsUtils} from 'pkg-tests-core';

describe(`Features`, () => {
describe(`Content-Addressed Index`, () => {
if (process.platform !== `win32`) {
it(`should install and repair read-only files without changing their permissions`,
makeTemporaryEnv({
dependencies: {readonly: `file:./readonly.tgz`},
}, {nodeLinker: `pnpm`}, async ({path, run}) => {
const fixture = ppath.join(path, `fixture`);
await xfs.mkdirPromise(fixture);
await xfs.writeJsonPromise(ppath.join(fixture, Filename.manifest), {name: `readonly`, version: `1.0.0`});
await xfs.writeFilePromise(ppath.join(fixture, `index.js`), `original`);
await xfs.chmodPromise(ppath.join(fixture, `index.js`), 0o555);
await fsUtils.packToFile(ppath.join(path, `readonly.tgz`), fixture, {virtualPath: ppath.resolve(`/package`)});

await run(`install`);
const installed = ppath.join(path, `node_modules/readonly/index.js`);
expect((await xfs.statPromise(installed)).mode & 0o777).toEqual(0o555);

// A failed install or external modification can leave a read-only entry needing repair.
await xfs.chmodPromise(installed, 0o755);
await xfs.writeFilePromise(installed, `modified`);
await xfs.chmodPromise(installed, 0o555);
await run(`install`, `--force`);

await expect(xfs.readFilePromise(installed, `utf8`)).resolves.toEqual(`original`);
expect((await xfs.statPromise(installed)).mode & 0o777).toEqual(0o555);
}),
);

test(
`it should preserve executable mode when installing`,
makeTemporaryEnv({
Expand Down
Loading