formacao
This commit is contained in:
+47
-19
@@ -54,6 +54,7 @@ class PackJob {
|
||||
stat;
|
||||
readdir;
|
||||
pending = false;
|
||||
pendingLink = false;
|
||||
ignore = false;
|
||||
piped = false;
|
||||
constructor(path, absolute) {
|
||||
@@ -65,12 +66,12 @@ exports.PackJob = PackJob;
|
||||
const minipass_1 = require("minipass");
|
||||
const zlib = __importStar(require("minizlib"));
|
||||
const yallist_1 = require("yallist");
|
||||
const read_entry_js_1 = require("./read-entry.js");
|
||||
const warn_method_js_1 = require("./warn-method.js");
|
||||
const EOF = Buffer.alloc(1024);
|
||||
const ONSTAT = Symbol('onStat');
|
||||
const ENDED = Symbol('ended');
|
||||
const QUEUE = Symbol('queue');
|
||||
const PENDINGLINKS = Symbol('pendingLinks');
|
||||
const CURRENT = Symbol('current');
|
||||
const PROCESS = Symbol('process');
|
||||
const PROCESSING = Symbol('processing');
|
||||
@@ -122,11 +123,11 @@ class Pack extends minipass_1.Minipass {
|
||||
// class, but then we'd have to be tracking the tail of the queue the
|
||||
// whole time, and Yallist just does that for us anyway.
|
||||
[QUEUE];
|
||||
[PENDINGLINKS] = new Map();
|
||||
[JOBS] = 0;
|
||||
[PROCESSING] = false;
|
||||
[ENDED] = false;
|
||||
constructor(opt = {}) {
|
||||
//@ts-ignore
|
||||
super();
|
||||
this.opt = opt;
|
||||
this.file = opt.file || '';
|
||||
@@ -146,9 +147,7 @@ class Pack extends minipass_1.Minipass {
|
||||
}
|
||||
this.portable = !!opt.portable;
|
||||
if (opt.gzip || opt.brotli || opt.zstd) {
|
||||
if ((opt.gzip ? 1 : 0) +
|
||||
(opt.brotli ? 1 : 0) +
|
||||
(opt.zstd ? 1 : 0) >
|
||||
if ((opt.gzip ? 1 : 0) + (opt.brotli ? 1 : 0) + (opt.zstd ? 1 : 0) >
|
||||
1) {
|
||||
throw new TypeError('gzip, brotli, zstd are mutually exclusive');
|
||||
}
|
||||
@@ -230,11 +229,11 @@ class Pack extends minipass_1.Minipass {
|
||||
if (this[ENDED]) {
|
||||
throw new Error('write after end');
|
||||
}
|
||||
if (path instanceof read_entry_js_1.ReadEntry) {
|
||||
this[ADDTARENTRY](path);
|
||||
if (typeof path === 'string') {
|
||||
this[ADDFSENTRY](path);
|
||||
}
|
||||
else {
|
||||
this[ADDFSENTRY](path);
|
||||
this[ADDTARENTRY](path);
|
||||
}
|
||||
return this.flowing;
|
||||
}
|
||||
@@ -282,14 +281,26 @@ class Pack extends minipass_1.Minipass {
|
||||
}
|
||||
else if (stat.isFile() &&
|
||||
stat.nlink > 1 &&
|
||||
job === this[CURRENT] &&
|
||||
!this.linkCache.get(`${stat.dev}:${stat.ino}`) &&
|
||||
!this.sync) {
|
||||
// if it's not filtered, and it's a new File entry,
|
||||
// jump the queue in case any pending Link entries are about
|
||||
// to try to link to it. This prevents a hardlink from coming ahead
|
||||
// of its target in the archive.
|
||||
this[PROCESSJOB](job);
|
||||
// if it's not filtered, and it's a new File entry, and next anyway
|
||||
// process right away in case any pending Link entries are about
|
||||
// to try to link to it.
|
||||
if (job === this[CURRENT]) {
|
||||
this[PROCESSJOB](job);
|
||||
}
|
||||
else {
|
||||
// if it's NOT the current entry, it needs to be deferred,
|
||||
// so that the link target can be built first.
|
||||
const key = `${stat.dev}:${stat.ino}`;
|
||||
const pending = this[PENDINGLINKS].get(key);
|
||||
if (pending)
|
||||
pending.push(job);
|
||||
else
|
||||
this[PENDINGLINKS].set(key, [job]);
|
||||
job.pendingLink = true;
|
||||
job.pending = true;
|
||||
}
|
||||
}
|
||||
this[PROCESS]();
|
||||
}
|
||||
@@ -324,7 +335,7 @@ class Pack extends minipass_1.Minipass {
|
||||
}
|
||||
}
|
||||
this[PROCESSING] = false;
|
||||
if (this[ENDED] && !this[QUEUE].length && this[JOBS] === 0) {
|
||||
if (this[ENDED] && this[QUEUE].length === 0 && this[JOBS] === 0) {
|
||||
if (this.zip) {
|
||||
this.zip.end(EOF);
|
||||
}
|
||||
@@ -337,12 +348,31 @@ class Pack extends minipass_1.Minipass {
|
||||
get [CURRENT]() {
|
||||
return this[QUEUE] && this[QUEUE].head && this[QUEUE].head.value;
|
||||
}
|
||||
[JOBDONE](_job) {
|
||||
[JOBDONE](job) {
|
||||
this[QUEUE].shift();
|
||||
this[JOBS] -= 1;
|
||||
const { stat } = job;
|
||||
if (stat && stat.isFile() && stat.nlink > 1) {
|
||||
// might be a file with pending links
|
||||
const key = `${stat.dev}:${stat.ino}`;
|
||||
const pending = this[PENDINGLINKS].get(key);
|
||||
if (pending) {
|
||||
this[PENDINGLINKS].delete(key);
|
||||
for (const job of pending) {
|
||||
job.pending = false;
|
||||
this[PROCESSJOB](job);
|
||||
}
|
||||
}
|
||||
}
|
||||
this[PROCESS]();
|
||||
}
|
||||
[PROCESSJOB](job) {
|
||||
if (job.pending && job.pendingLink && job === this[CURRENT]) {
|
||||
// At least one of the links to this file are not being included
|
||||
// in the tarball, so we need to just proceed.
|
||||
job.pending = false;
|
||||
job.pendingLink = false;
|
||||
}
|
||||
if (job.pending) {
|
||||
return;
|
||||
}
|
||||
@@ -368,9 +398,7 @@ class Pack extends minipass_1.Minipass {
|
||||
if (job.ignore) {
|
||||
return;
|
||||
}
|
||||
if (!this.noDirRecurse &&
|
||||
job.stat.isDirectory() &&
|
||||
!job.readdir) {
|
||||
if (!this.noDirRecurse && job.stat.isDirectory() && !job.readdir) {
|
||||
const rc = this.readdirCache.get(job.absolute);
|
||||
if (rc) {
|
||||
this[ONREADDIR](job, rc);
|
||||
|
||||
Reference in New Issue
Block a user