8000 Fix: check if an existing file is a symlink during symlink testing by emmercm · Pull Request #1009 · emmercm/igir · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix: check if an existing file is a symlink during symlink testing #1009

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

Merged
merged 2 commits into from
Mar 18, 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
4 changes: 4 additions & 0 deletions src/modules/candidateWriter.ts
8000
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,10 @@ export default class CandidateWriter extends Module {
return 'doesn\'t exist';
}

if (!await fsPoly.isSymlink(linkPath)) {
return 'is not a symlink';
}

const existingSourcePath = await fsPoly.readlink(linkPath);
if (path.normalize(existingSourcePath) !== path.normalize(expectedTargetPath)) {
return `has the target path '${existingSourcePath}', expected '${expectedTargetPath}`;
Expand Down
44 changes: 44 additions & 0 deletions test/modules/candidateWriter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1410,6 +1410,50 @@ describe.each([
await expect(walkAndStat(inputTemp)).resolves.toMatchObject(inputFilesBefore);
});
});

it('should write if the output is not expected and overwriting invalid', async () => {
await copyFixturesToTemp(async (inputTemp, outputTemp) => {
// Given
const options = new Options({ commands: ['link', 'test'], symlink });
const inputFilesBefore = await walkAndStat(inputTemp);
await expect(walkAndStat(outputTemp)).resolves.toHaveLength(0);

// And we've written once
await candidateWriter(options, inputTemp, '**/*', undefined, outputTemp);

// And files were written
const outputFilesBefore = await walkAndStat(outputTemp);
expect(outputFilesBefore).not.toHaveLength(0);
for (const [, stats] of outputFilesBefore) {
expect(stats.isSymbolicLink()).toEqual(symlink);
}

// And the files are made invalid
await Promise.all(outputFilesBefore.map(async ([filePath]) => {
const resolvedPath = path.join(outputTemp, filePath);
await fsPoly.rm(resolvedPath);
await fsPoly.touch(resolvedPath);
}));

// When we write again
await candidateWriter({
...options,
overwriteInvalid: true,
}, inputTemp, '**/*', undefined, outputTemp);

// Then the output was touched
const outputFilesAfter = await walkAndStat(outputTemp);
expect(outputFilesAfter.map((pair) => pair[0]))
.toEqual(outputFilesBefore.map((pair) => pair[0]));
expect(outputFilesAfter).not.toEqual(outputFilesBefore);
for (const [, stats] of outputFilesAfter) {
expect(stats.isSymbolicLink()).toEqual(symlink);
}

// And the input files weren't touched
await expect(walkAndStat(inputTemp)).resolves.toMatchObject(inputFilesBefore);
});
});
});

it('should write relative symlinks', async () => {
Expand Down
0