tgz: preserve mode

This commit is contained in:
Girish Ramakrishnan
2024-07-11 17:22:13 +02:00
parent 19100c7999
commit 8754a208b1

View File

@@ -100,7 +100,7 @@ async function tarPack(dataLayout, encryption, uploader, progressCallback) {
if (!handle) { debug(`tarPack: skipping file, could not open ${abspath}: ${openError.message}`); continue; }
const [statError, stat] = await safe(handle.stat());
if (!stat) { debug(`tarPack: skipping file, could not stat ${abspath}: ${statError.message}`); continue; }
const header = { name: headerName, type: 'file', size: stat.size, uid: process.getuid(), gid: process.getgid() };
const header = { name: headerName, type: 'file', mode: stat.mode, size: stat.size, uid: process.getuid(), gid: process.getgid() };
if (stat.size > 8589934590 || entry.name.length > 99) header.pax = { size: stat.size };
const input = handle.createReadStream({ autoClose: true });
await addToPack(pack, header, { input });
@@ -152,6 +152,7 @@ async function tarExtract(inStream, dataLayout, encryption, progressCallback) {
} else if (header.type === 'file') {
const output = fs.createWriteStream(abspath);
[error] = await safe(stream.pipeline(entryStream, output));
if (!error) [error] = await safe(fs.promises.chmod(abspath, header.mode));
} else if (header.type === 'symlink') {
await safe(fs.promises.unlink(abspath)); // remove any link created from previous failed extract
[error] = await safe(fs.promises.symlink(header.linkname, abspath));