Merge pull request #1302 from balena-io/1301-link-error

Use lstat rather than stat to avoid error with symlinks in sync
This commit is contained in:
CameronDiver 2020-05-06 16:39:24 +01:00 committed by GitHub
commit 32581a8198
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -99,10 +99,6 @@ async function tarDirectory(
const entries = await fs.readdir(path);
for (const entry of entries) {
const newPath = Path.resolve(path, entry);
const stat = await fs.stat(newPath);
if (stat.isDirectory()) {
await add(newPath);
} else {
// Here we filter the things we don't want
if (
newPath.includes('node_modules/') ||
@ -112,7 +108,12 @@ async function tarDirectory(
) {
continue;
}
// We use lstat here, otherwise an error will be
// thrown on a symbolic link
const stat = await fs.lstat(newPath);
if (stat.isDirectory()) {
await add(newPath);
} else {
if (newPath.endsWith('Dockerfile')) {
pack.entry(
{ name: 'Dockerfile', mode: stat.mode, size: stat.size },