Skip to content

Commit

Permalink
deps: tar@6.1.12
Browse files Browse the repository at this point in the history
  • Loading branch information
wraithgar committed Nov 2, 2022
1 parent 2fef570 commit 5730d17
Show file tree
Hide file tree
Showing 22 changed files with 589 additions and 357 deletions.
25 changes: 16 additions & 9 deletions node_modules/tar/lib/create.js
Expand Up @@ -9,24 +9,29 @@ const t = require('./list.js')
const path = require('path')

module.exports = (opt_, files, cb) => {
if (typeof files === 'function')
if (typeof files === 'function') {
cb = files
}

if (Array.isArray(opt_))
if (Array.isArray(opt_)) {
files = opt_, opt_ = {}
}

if (!files || !Array.isArray(files) || !files.length)
if (!files || !Array.isArray(files) || !files.length) {
throw new TypeError('no files or directories specified')
}

files = Array.from(files)

const opt = hlo(opt_)

if (opt.sync && typeof cb === 'function')
if (opt.sync && typeof cb === 'function') {
throw new TypeError('callback not supported for sync tar functions')
}

if (!opt.file && typeof cb === 'function')
if (!opt.file && typeof cb === 'function') {
throw new TypeError('callback only supported with file option')
}

return opt.file && opt.sync ? createFileSync(opt, files)
: opt.file ? createFile(opt, files, cb)
Expand Down Expand Up @@ -65,13 +70,14 @@ const addFilesSync = (p, files) => {
files.forEach(file => {
if (file.charAt(0) === '@') {
t({
file: path.resolve(p.cwd, file.substr(1)),
file: path.resolve(p.cwd, file.slice(1)),
sync: true,
noResume: true,
onentry: entry => p.add(entry),
})
} else
} else {
p.add(file)
}
})
p.end()
}
Expand All @@ -81,12 +87,13 @@ const addFilesAsync = (p, files) => {
const file = files.shift()
if (file.charAt(0) === '@') {
return t({
file: path.resolve(p.cwd, file.substr(1)),
file: path.resolve(p.cwd, file.slice(1)),
noResume: true,
onentry: entry => p.add(entry),
}).then(_ => addFilesAsync(p, files))
} else
} else {
p.add(file)
}
}
p.end()
}
Expand Down
26 changes: 16 additions & 10 deletions node_modules/tar/lib/extract.js
Expand Up @@ -9,29 +9,35 @@ const path = require('path')
const stripSlash = require('./strip-trailing-slashes.js')

module.exports = (opt_, files, cb) => {
if (typeof opt_ === 'function')
if (typeof opt_ === 'function') {
cb = opt_, files = null, opt_ = {}
else if (Array.isArray(opt_))
} else if (Array.isArray(opt_)) {
files = opt_, opt_ = {}
}

if (typeof files === 'function')
if (typeof files === 'function') {
cb = files, files = null
}

if (!files)
if (!files) {
files = []
else
} else {
files = Array.from(files)
}

const opt = hlo(opt_)

if (opt.sync && typeof cb === 'function')
if (opt.sync && typeof cb === 'function') {
throw new TypeError('callback not supported for sync tar functions')
}

if (!opt.file && typeof cb === 'function')
if (!opt.file && typeof cb === 'function') {
throw new TypeError('callback only supported with file option')
}

if (files.length)
if (files.length) {
filesFilter(opt, files)
}

return opt.file && opt.sync ? extractFileSync(opt)
: opt.file ? extractFile(opt, cb)
Expand Down Expand Up @@ -87,9 +93,9 @@ const extractFile = (opt, cb) => {
// This trades a zero-byte read() syscall for a stat
// However, it will usually result in less memory allocation
fs.stat(file, (er, stat) => {
if (er)
if (er) {
reject(er)
else {
} else {
const stream = new fsm.ReadStream(file, {
readSize: readSize,
size: stat.size,
Expand Down
84 changes: 50 additions & 34 deletions node_modules/tar/lib/header.js
Expand Up @@ -34,18 +34,21 @@ class Header {
this.atime = null
this.ctime = null

if (Buffer.isBuffer(data))
if (Buffer.isBuffer(data)) {
this.decode(data, off || 0, ex, gex)
else if (data)
} else if (data) {
this.set(data)
}
}

decode (buf, off, ex, gex) {
if (!off)
if (!off) {
off = 0
}

if (!buf || !(buf.length >= off + 512))
if (!buf || !(buf.length >= off + 512)) {
throw new Error('need 512 bytes for header')
}

this.path = decString(buf, off, 100)
this.mode = decNumber(buf, off + 100, 8)
Expand All @@ -62,18 +65,21 @@ class Header {

// old tar versions marked dirs as a file with a trailing /
this[TYPE] = decString(buf, off + 156, 1)
if (this[TYPE] === '')
if (this[TYPE] === '') {
this[TYPE] = '0'
if (this[TYPE] === '0' && this.path.substr(-1) === '/')
}
if (this[TYPE] === '0' && this.path.slice(-1) === '/') {
this[TYPE] = '5'
}

// tar implementations sometimes incorrectly put the stat(dir).size
// as the size in the tarball, even though Directory entries are
// not able to have any body at all. In the very rare chance that
// it actually DOES have a body, we weren't going to do anything with
// it anyway, and it'll just be a warning about an invalid header.
if (this[TYPE] === '5')
if (this[TYPE] === '5') {
this.size = 0
}

this.linkpath = decString(buf, off + 157, 100)
if (buf.slice(off + 257, off + 265).toString() === 'ustar\u000000') {
Expand All @@ -87,32 +93,37 @@ class Header {
this.path = prefix + '/' + this.path
} else {
const prefix = decString(buf, off + 345, 130)
if (prefix)
if (prefix) {
this.path = prefix + '/' + this.path
}
this.atime = decDate(buf, off + 476, 12)
this.ctime = decDate(buf, off + 488, 12)
}
}

let sum = 8 * 0x20
for (let i = off; i < off + 148; i++)
for (let i = off; i < off + 148; i++) {
sum += buf[i]
}

for (let i = off + 156; i < off + 512; i++)
for (let i = off + 156; i < off + 512; i++) {
sum += buf[i]
}

this.cksumValid = sum === this.cksum
if (this.cksum === null && sum === 8 * 0x20)
if (this.cksum === null && sum === 8 * 0x20) {
this.nullBlock = true
}
}

[SLURP] (ex, global) {
for (const k in ex) {
// we slurp in everything except for the path attribute in
// a global extended header, because that's weird.
if (ex[k] !== null && ex[k] !== undefined &&
!(global && k === 'path'))
!(global && k === 'path')) {
this[k] = ex[k]
}
}
}

Expand All @@ -122,11 +133,13 @@ class Header {
off = 0
}

if (!off)
if (!off) {
off = 0
}

if (!(buf.length >= off + 512))
if (!(buf.length >= off + 512)) {
throw new Error('need 512 bytes for header')
}

const prefixSize = this.ctime || this.atime ? 130 : 155
const split = splitPrefix(this.path || '', prefixSize)
Expand All @@ -148,20 +161,22 @@ class Header {
this.needPax = encNumber(buf, off + 329, 8, this.devmaj) || this.needPax
this.needPax = encNumber(buf, off + 337, 8, this.devmin) || this.needPax
this.needPax = encString(buf, off + 345, prefixSize, prefix) || this.needPax
if (buf[off + 475] !== 0)
if (buf[off + 475] !== 0) {
this.needPax = encString(buf, off + 345, 155, prefix) || this.needPax
else {
} else {
this.needPax = encString(buf, off + 345, 130, prefix) || this.needPax
this.needPax = encDate(buf, off + 476, 12, this.atime) || this.needPax
this.needPax = encDate(buf, off + 488, 12, this.ctime) || this.needPax
}

let sum = 8 * 0x20
for (let i = off; i < off + 148; i++)
for (let i = off; i < off + 148; i++) {
sum += buf[i]
}

for (let i = off + 156; i < off + 512; i++)
for (let i = off + 156; i < off + 512; i++) {
sum += buf[i]
}

this.cksum = sum
encNumber(buf, off + 148, 8, this.cksum)
Expand All @@ -172,8 +187,9 @@ class Header {

set (data) {
for (const i in data) {
if (data[i] !== null && data[i] !== undefined)
if (data[i] !== null && data[i] !== undefined) {
this[i] = data[i]
}
}
}

Expand All @@ -186,10 +202,11 @@ class Header {
}

set type (type) {
if (types.code.has(type))
if (types.code.has(type)) {
this[TYPE] = types.code.get(type)
else
} else {
this[TYPE] = type
}
}
}

Expand All @@ -200,34 +217,33 @@ const splitPrefix = (p, prefixSize) => {
let ret
const root = pathModule.parse(p).root || '.'

if (Buffer.byteLength(pp) < pathSize)
if (Buffer.byteLength(pp) < pathSize) {
ret = [pp, prefix, false]
else {
} else {
// first set prefix to the dir, and path to the base
prefix = pathModule.dirname(pp)
pp = pathModule.basename(pp)

do {
// both fit!
if (Buffer.byteLength(pp) <= pathSize &&
Buffer.byteLength(prefix) <= prefixSize)
Buffer.byteLength(prefix) <= prefixSize) {
// both fit!
ret = [pp, prefix, false]

// prefix fits in prefix, but path doesn't fit in path
else if (Buffer.byteLength(pp) > pathSize &&
Buffer.byteLength(prefix) <= prefixSize)
ret = [pp.substr(0, pathSize - 1), prefix, true]

else {
} else if (Buffer.byteLength(pp) > pathSize &&
Buffer.byteLength(prefix) <= prefixSize) {
// prefix fits in prefix, but path doesn't fit in path
ret = [pp.slice(0, pathSize - 1), prefix, true]
} else {
// make path take a bit from prefix
pp = pathModule.join(pathModule.basename(prefix), pp)
prefix = pathModule.dirname(prefix)
}
} while (prefix !== root && !ret)

// at this point, found no resolution, just truncate
if (!ret)
ret = [p.substr(0, pathSize - 1), '', true]
if (!ret) {
ret = [p.slice(0, pathSize - 1), '', true]
}
}
return ret
}
Expand Down

0 comments on commit 5730d17

Please sign in to comment.