formacao
This commit is contained in:
+48
-20
@@ -15,6 +15,7 @@ export class PackJob {
|
||||
stat;
|
||||
readdir;
|
||||
pending = false;
|
||||
pendingLink = false;
|
||||
ignore = false;
|
||||
piped = false;
|
||||
constructor(path, absolute) {
|
||||
@@ -25,12 +26,12 @@ export class PackJob {
|
||||
import { Minipass } from 'minipass';
|
||||
import * as zlib from 'minizlib';
|
||||
import { Yallist } from 'yallist';
|
||||
import { ReadEntry } from './read-entry.js';
|
||||
import { warnMethod, } from './warn-method.js';
|
||||
import { warnMethod } from './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');
|
||||
@@ -82,11 +83,11 @@ export class Pack extends 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 || '';
|
||||
@@ -106,9 +107,7 @@ export class Pack extends 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');
|
||||
}
|
||||
@@ -190,11 +189,11 @@ export class Pack extends Minipass {
|
||||
if (this[ENDED]) {
|
||||
throw new Error('write after end');
|
||||
}
|
||||
if (path instanceof ReadEntry) {
|
||||
this[ADDTARENTRY](path);
|
||||
if (typeof path === 'string') {
|
||||
this[ADDFSENTRY](path);
|
||||
}
|
||||
else {
|
||||
this[ADDFSENTRY](path);
|
||||
this[ADDTARENTRY](path);
|
||||
}
|
||||
return this.flowing;
|
||||
}
|
||||
@@ -242,14 +241,26 @@ export class Pack extends 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]();
|
||||
}
|
||||
@@ -284,7 +295,7 @@ export class Pack extends 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);
|
||||
}
|
||||
@@ -297,12 +308,31 @@ export class Pack extends 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;
|
||||
}
|
||||
@@ -328,9 +358,7 @@ export class Pack extends 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