chore: copy symlinks as is, rather than copying the realpath into the place

Signed-off-by: blam <ben@blam.sh>
This commit is contained in:
blam
2022-07-07 19:20:52 +02:00
parent 07b21ed7f9
commit 5185c58bf5
2 changed files with 18 additions and 2 deletions
@@ -186,6 +186,10 @@ describe('fetch:template', () => {
},
'.${{ values.name }}': '${{ values.itemList | dump }}',
'a-binary-file.png': aBinaryFile,
symlink: mockFs.symlink({
path: 'a-binary-file.png',
}),
'{% if values.showDummyFile %}dummy-file.txt{% else %}{% endif %}':
'dummy file',
'${{ "dummy-file2.txt" if values.showDummyFile else "" }}':
@@ -265,6 +269,17 @@ describe('fetch:template', () => {
.then(fObj => fObj.mode),
).resolves.toEqual(parseInt('100755', 8));
});
it('copies file symlinks as-is without processing them', async () => {
await expect(
fs
.lstat(`${workspacePath}/target/symlink`)
.then(i => i.isSymbolicLink()),
).resolves.toBe(true);
await expect(
fs.realpath(`${workspacePath}/target/symlink`),
).resolves.toBe(`${workspacePath}/target/a-binary-file.png`);
});
});
describe('copyWithoutRender', () => {
@@ -229,10 +229,11 @@ export function createFetchTemplateAction(options: {
await fs.ensureDir(outputPath);
} else {
const inputFilePath = resolveSafeChildPath(templateDir, location);
const stats = await fs.promises.lstat(inputFilePath);
if (await isBinaryFile(inputFilePath)) {
if (stats.isSymbolicLink() || (await isBinaryFile(inputFilePath))) {
ctx.logger.info(
`Copying binary file ${location} to template output path.`,
`Copying file binary or symbolic link at ${location}, to template output path.`,
);
await fs.copy(inputFilePath, outputPath);
} else {