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

Fixes package linking when a filename casing changes #3843

Merged
merged 2 commits into from
Jul 7, 2017
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
13 changes: 13 additions & 0 deletions __tests__/commands/install/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,19 @@ async function mockConstants(base: Config, mocks: Object, cb: (config: Config) =
beforeEach(request.__resetAuthedRequests);
afterEach(request.__resetAuthedRequests);

test.concurrent('installing a package with a renamed file should not delete it', async () => {
await runInstall({}, 'case-sensitivity', async (config, reporter): Promise<void> => {
const pkgJson = await fs.readJson(`${config.cwd}/package.json`);
pkgJson.dependencies['pkg'] = 'file:./pkg-b';
await fs.writeFile(`${config.cwd}/package.json`, JSON.stringify(pkgJson));

const reInstall = new Install({}, config, reporter, await Lockfile.fromDirectory(config.cwd));
await reInstall.init();

expect(await fs.exists(`${config.cwd}/node_modules/pkg/state.js`)).toEqual(true);
});
});

test.concurrent('properly find and save build artifacts', async () => {
await runInstall({}, 'artifacts-finds-and-saves', async (config): Promise<void> => {
const integrity = await fs.readJson(path.join(config.cwd, 'node_modules', constants.INTEGRITY_FILENAME));
Expand Down
5 changes: 5 additions & 0 deletions __tests__/fixtures/install/case-sensitivity/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dependencies": {
"pkg": "file:./pkg-a"
}
}
1 change: 1 addition & 0 deletions __tests__/fixtures/install/case-sensitivity/pkg-a/State.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello World
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "pkg",
"version": "1.0.0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "pkg",
"version": "2.0.0"
}
1 change: 1 addition & 0 deletions __tests__/fixtures/install/case-sensitivity/pkg-b/state.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello World
30 changes: 18 additions & 12 deletions src/util/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ async function buildActionsForCopy(
}

for (const loc of possibleExtraneous) {
if (files.has(loc)) {
if (files.has(loc.toLowerCase())) {
possibleExtraneous.delete(loc);
}
}
Expand All @@ -163,12 +163,14 @@ async function buildActionsForCopy(
const {src, dest, type} = data;
const onFresh = data.onFresh || noop;
const onDone = data.onDone || noop;
if (files.has(dest)) {
// TODO https://github.com/yarnpkg/yarn/issues/3751
// related to bundled dependencies handling
reporter.warn(`The same file ${dest} can't be copied twice in one bulk copy`);

// TODO https://github.com/yarnpkg/yarn/issues/3751
// related to bundled dependencies handling
if (files.has(dest.toLowerCase())) {
reporter.warn(`The case-insensitive file ${dest} shouldn't be copied twice in one bulk copy`);
} else {
files.add(dest.toLowerCase());
}
files.add(dest);

if (type === 'symlink') {
await mkdirp(path.dirname(dest));
Expand Down Expand Up @@ -279,7 +281,7 @@ async function buildActionsForCopy(

const destParts = dest.split(path.sep);
while (destParts.length) {
files.add(destParts.join(path.sep));
files.add(destParts.join(path.sep).toLowerCase());
destParts.pop();
}

Expand Down Expand Up @@ -358,7 +360,7 @@ async function buildActionsForHardlink(
}

for (const loc of possibleExtraneous) {
if (files.has(loc)) {
if (files.has(loc.toLowerCase())) {
possibleExtraneous.delete(loc);
}
}
Expand All @@ -370,7 +372,7 @@ async function buildActionsForHardlink(
const {src, dest} = data;
const onFresh = data.onFresh || noop;
const onDone = data.onDone || noop;
if (files.has(dest)) {
if (files.has(dest.toLowerCase())) {
// Fixes issue https://github.com/yarnpkg/yarn/issues/2734
// When bulk hardlinking we have A -> B structure that we want to hardlink to A1 -> B1,
// package-linker passes that modules A1 and B1 need to be hardlinked,
Expand All @@ -379,7 +381,7 @@ async function buildActionsForHardlink(
onDone();
return;
}
files.add(dest);
files.add(dest.toLowerCase());

if (events.ignoreBasenames.indexOf(path.basename(src)) >= 0) {
// ignored file
Expand Down Expand Up @@ -463,7 +465,7 @@ async function buildActionsForHardlink(

const destParts = dest.split(path.sep);
while (destParts.length) {
files.add(destParts.join(path.sep));
files.add(destParts.join(path.sep).toLowerCase());
destParts.pop();
}

Expand Down Expand Up @@ -541,7 +543,11 @@ export async function copyBulk(
const cleanup = () => delete currentlyWriting[data.dest];
reporter.verbose(reporter.lang('verboseFileCopy', data.src, data.dest));
return (currentlyWriting[data.dest] = readFileBuffer(data.src)
.then(d => {
.then(async d => {
// we need to do this because of case-insensitive filesystems, which wouldn't properly
// change the file name in case of a file being renamed
await unlink(data.dest);
Copy link
Member

Choose a reason for hiding this comment

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

Great work, @arcanis.
I am a bit worried about the extra IO operation here.
What impact would it cause for normal installation?


return writeFile(data.dest, d, {mode: data.mode});
})
.then(() => {
Expand Down