mirror of
https://github.com/fooflington/selfdefined.git
synced 2025-06-12 13:41:40 +00:00
update
This commit is contained in:
12
node_modules/fs-extra/lib/util/buffer.js
generated
vendored
Normal file
12
node_modules/fs-extra/lib/util/buffer.js
generated
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
'use strict'
|
||||
/* eslint-disable node/no-deprecated-api */
|
||||
module.exports = function (size) {
|
||||
if (typeof Buffer.allocUnsafe === 'function') {
|
||||
try {
|
||||
return Buffer.allocUnsafe(size)
|
||||
} catch (e) {
|
||||
return new Buffer(size)
|
||||
}
|
||||
}
|
||||
return new Buffer(size)
|
||||
}
|
172
node_modules/fs-extra/lib/util/stat.js
generated
vendored
Normal file
172
node_modules/fs-extra/lib/util/stat.js
generated
vendored
Normal file
@ -0,0 +1,172 @@
|
||||
'use strict'
|
||||
|
||||
const fs = require('graceful-fs')
|
||||
const path = require('path')
|
||||
|
||||
const NODE_VERSION_MAJOR_WITH_BIGINT = 10
|
||||
const NODE_VERSION_MINOR_WITH_BIGINT = 5
|
||||
const NODE_VERSION_PATCH_WITH_BIGINT = 0
|
||||
const nodeVersion = process.versions.node.split('.')
|
||||
const nodeVersionMajor = Number.parseInt(nodeVersion[0], 10)
|
||||
const nodeVersionMinor = Number.parseInt(nodeVersion[1], 10)
|
||||
const nodeVersionPatch = Number.parseInt(nodeVersion[2], 10)
|
||||
|
||||
function nodeSupportsBigInt () {
|
||||
if (nodeVersionMajor > NODE_VERSION_MAJOR_WITH_BIGINT) {
|
||||
return true
|
||||
} else if (nodeVersionMajor === NODE_VERSION_MAJOR_WITH_BIGINT) {
|
||||
if (nodeVersionMinor > NODE_VERSION_MINOR_WITH_BIGINT) {
|
||||
return true
|
||||
} else if (nodeVersionMinor === NODE_VERSION_MINOR_WITH_BIGINT) {
|
||||
if (nodeVersionPatch >= NODE_VERSION_PATCH_WITH_BIGINT) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
function getStats (src, dest, cb) {
|
||||
if (nodeSupportsBigInt()) {
|
||||
fs.stat(src, { bigint: true }, (err, srcStat) => {
|
||||
if (err) return cb(err)
|
||||
fs.stat(dest, { bigint: true }, (err, destStat) => {
|
||||
if (err) {
|
||||
if (err.code === 'ENOENT') return cb(null, { srcStat, destStat: null })
|
||||
return cb(err)
|
||||
}
|
||||
return cb(null, { srcStat, destStat })
|
||||
})
|
||||
})
|
||||
} else {
|
||||
fs.stat(src, (err, srcStat) => {
|
||||
if (err) return cb(err)
|
||||
fs.stat(dest, (err, destStat) => {
|
||||
if (err) {
|
||||
if (err.code === 'ENOENT') return cb(null, { srcStat, destStat: null })
|
||||
return cb(err)
|
||||
}
|
||||
return cb(null, { srcStat, destStat })
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function getStatsSync (src, dest) {
|
||||
let srcStat, destStat
|
||||
if (nodeSupportsBigInt()) {
|
||||
srcStat = fs.statSync(src, { bigint: true })
|
||||
} else {
|
||||
srcStat = fs.statSync(src)
|
||||
}
|
||||
try {
|
||||
if (nodeSupportsBigInt()) {
|
||||
destStat = fs.statSync(dest, { bigint: true })
|
||||
} else {
|
||||
destStat = fs.statSync(dest)
|
||||
}
|
||||
} catch (err) {
|
||||
if (err.code === 'ENOENT') return { srcStat, destStat: null }
|
||||
throw err
|
||||
}
|
||||
return { srcStat, destStat }
|
||||
}
|
||||
|
||||
function checkPaths (src, dest, funcName, cb) {
|
||||
getStats(src, dest, (err, stats) => {
|
||||
if (err) return cb(err)
|
||||
const { srcStat, destStat } = stats
|
||||
if (destStat && destStat.ino && destStat.dev && destStat.ino === srcStat.ino && destStat.dev === srcStat.dev) {
|
||||
return cb(new Error('Source and destination must not be the same.'))
|
||||
}
|
||||
if (srcStat.isDirectory() && isSrcSubdir(src, dest)) {
|
||||
return cb(new Error(errMsg(src, dest, funcName)))
|
||||
}
|
||||
return cb(null, { srcStat, destStat })
|
||||
})
|
||||
}
|
||||
|
||||
function checkPathsSync (src, dest, funcName) {
|
||||
const { srcStat, destStat } = getStatsSync(src, dest)
|
||||
if (destStat && destStat.ino && destStat.dev && destStat.ino === srcStat.ino && destStat.dev === srcStat.dev) {
|
||||
throw new Error('Source and destination must not be the same.')
|
||||
}
|
||||
if (srcStat.isDirectory() && isSrcSubdir(src, dest)) {
|
||||
throw new Error(errMsg(src, dest, funcName))
|
||||
}
|
||||
return { srcStat, destStat }
|
||||
}
|
||||
|
||||
// recursively check if dest parent is a subdirectory of src.
|
||||
// It works for all file types including symlinks since it
|
||||
// checks the src and dest inodes. It starts from the deepest
|
||||
// parent and stops once it reaches the src parent or the root path.
|
||||
function checkParentPaths (src, srcStat, dest, funcName, cb) {
|
||||
const srcParent = path.resolve(path.dirname(src))
|
||||
const destParent = path.resolve(path.dirname(dest))
|
||||
if (destParent === srcParent || destParent === path.parse(destParent).root) return cb()
|
||||
if (nodeSupportsBigInt()) {
|
||||
fs.stat(destParent, { bigint: true }, (err, destStat) => {
|
||||
if (err) {
|
||||
if (err.code === 'ENOENT') return cb()
|
||||
return cb(err)
|
||||
}
|
||||
if (destStat.ino && destStat.dev && destStat.ino === srcStat.ino && destStat.dev === srcStat.dev) {
|
||||
return cb(new Error(errMsg(src, dest, funcName)))
|
||||
}
|
||||
return checkParentPaths(src, srcStat, destParent, funcName, cb)
|
||||
})
|
||||
} else {
|
||||
fs.stat(destParent, (err, destStat) => {
|
||||
if (err) {
|
||||
if (err.code === 'ENOENT') return cb()
|
||||
return cb(err)
|
||||
}
|
||||
if (destStat.ino && destStat.dev && destStat.ino === srcStat.ino && destStat.dev === srcStat.dev) {
|
||||
return cb(new Error(errMsg(src, dest, funcName)))
|
||||
}
|
||||
return checkParentPaths(src, srcStat, destParent, funcName, cb)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function checkParentPathsSync (src, srcStat, dest, funcName) {
|
||||
const srcParent = path.resolve(path.dirname(src))
|
||||
const destParent = path.resolve(path.dirname(dest))
|
||||
if (destParent === srcParent || destParent === path.parse(destParent).root) return
|
||||
let destStat
|
||||
try {
|
||||
if (nodeSupportsBigInt()) {
|
||||
destStat = fs.statSync(destParent, { bigint: true })
|
||||
} else {
|
||||
destStat = fs.statSync(destParent)
|
||||
}
|
||||
} catch (err) {
|
||||
if (err.code === 'ENOENT') return
|
||||
throw err
|
||||
}
|
||||
if (destStat.ino && destStat.dev && destStat.ino === srcStat.ino && destStat.dev === srcStat.dev) {
|
||||
throw new Error(errMsg(src, dest, funcName))
|
||||
}
|
||||
return checkParentPathsSync(src, srcStat, destParent, funcName)
|
||||
}
|
||||
|
||||
// return true if dest is a subdir of src, otherwise false.
|
||||
// It only checks the path strings.
|
||||
function isSrcSubdir (src, dest) {
|
||||
const srcArr = path.resolve(src).split(path.sep).filter(i => i)
|
||||
const destArr = path.resolve(dest).split(path.sep).filter(i => i)
|
||||
return srcArr.reduce((acc, cur, i) => acc && destArr[i] === cur, true)
|
||||
}
|
||||
|
||||
function errMsg (src, dest, funcName) {
|
||||
return `Cannot ${funcName} '${src}' to a subdirectory of itself, '${dest}'.`
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
checkPaths,
|
||||
checkPathsSync,
|
||||
checkParentPaths,
|
||||
checkParentPathsSync,
|
||||
isSrcSubdir
|
||||
}
|
79
node_modules/fs-extra/lib/util/utimes.js
generated
vendored
Normal file
79
node_modules/fs-extra/lib/util/utimes.js
generated
vendored
Normal file
@ -0,0 +1,79 @@
|
||||
'use strict'
|
||||
|
||||
const fs = require('graceful-fs')
|
||||
const os = require('os')
|
||||
const path = require('path')
|
||||
|
||||
// HFS, ext{2,3}, FAT do not, Node.js v0.10 does not
|
||||
function hasMillisResSync () {
|
||||
let tmpfile = path.join('millis-test-sync' + Date.now().toString() + Math.random().toString().slice(2))
|
||||
tmpfile = path.join(os.tmpdir(), tmpfile)
|
||||
|
||||
// 550 millis past UNIX epoch
|
||||
const d = new Date(1435410243862)
|
||||
fs.writeFileSync(tmpfile, 'https://github.com/jprichardson/node-fs-extra/pull/141')
|
||||
const fd = fs.openSync(tmpfile, 'r+')
|
||||
fs.futimesSync(fd, d, d)
|
||||
fs.closeSync(fd)
|
||||
return fs.statSync(tmpfile).mtime > 1435410243000
|
||||
}
|
||||
|
||||
function hasMillisRes (callback) {
|
||||
let tmpfile = path.join('millis-test' + Date.now().toString() + Math.random().toString().slice(2))
|
||||
tmpfile = path.join(os.tmpdir(), tmpfile)
|
||||
|
||||
// 550 millis past UNIX epoch
|
||||
const d = new Date(1435410243862)
|
||||
fs.writeFile(tmpfile, 'https://github.com/jprichardson/node-fs-extra/pull/141', err => {
|
||||
if (err) return callback(err)
|
||||
fs.open(tmpfile, 'r+', (err, fd) => {
|
||||
if (err) return callback(err)
|
||||
fs.futimes(fd, d, d, err => {
|
||||
if (err) return callback(err)
|
||||
fs.close(fd, err => {
|
||||
if (err) return callback(err)
|
||||
fs.stat(tmpfile, (err, stats) => {
|
||||
if (err) return callback(err)
|
||||
callback(null, stats.mtime > 1435410243000)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function timeRemoveMillis (timestamp) {
|
||||
if (typeof timestamp === 'number') {
|
||||
return Math.floor(timestamp / 1000) * 1000
|
||||
} else if (timestamp instanceof Date) {
|
||||
return new Date(Math.floor(timestamp.getTime() / 1000) * 1000)
|
||||
} else {
|
||||
throw new Error('fs-extra: timeRemoveMillis() unknown parameter type')
|
||||
}
|
||||
}
|
||||
|
||||
function utimesMillis (path, atime, mtime, callback) {
|
||||
// if (!HAS_MILLIS_RES) return fs.utimes(path, atime, mtime, callback)
|
||||
fs.open(path, 'r+', (err, fd) => {
|
||||
if (err) return callback(err)
|
||||
fs.futimes(fd, atime, mtime, futimesErr => {
|
||||
fs.close(fd, closeErr => {
|
||||
if (callback) callback(futimesErr || closeErr)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function utimesMillisSync (path, atime, mtime) {
|
||||
const fd = fs.openSync(path, 'r+')
|
||||
fs.futimesSync(fd, atime, mtime)
|
||||
return fs.closeSync(fd)
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
hasMillisRes,
|
||||
hasMillisResSync,
|
||||
timeRemoveMillis,
|
||||
utimesMillis,
|
||||
utimesMillisSync
|
||||
}
|
Reference in New Issue
Block a user