1
0
mirror of https://github.com/S2-/gitlit synced 2025-08-04 05:10:05 +02:00

update dependencies

This commit is contained in:
s2
2018-10-10 15:11:12 +02:00
parent da4083f574
commit 5c55c54b71
90877 changed files with 339776 additions and 33677 deletions

View File

@@ -1,26 +1,28 @@
var fs = require('graceful-fs')
'use strict'
var BUF_LENGTH = 64 * 1024
var _buff = new Buffer(BUF_LENGTH)
const fs = require('graceful-fs')
const BUF_LENGTH = 64 * 1024
const _buff = require('../util/buffer')(BUF_LENGTH)
function copyFileSync (srcFile, destFile, options) {
var clobber = options.clobber
var preserveTimestamps = options.preserveTimestamps
const overwrite = options.overwrite
const errorOnExist = options.errorOnExist
const preserveTimestamps = options.preserveTimestamps
if (fs.existsSync(destFile)) {
if (clobber) {
fs.chmodSync(destFile, parseInt('777', 8))
if (overwrite) {
fs.unlinkSync(destFile)
} else {
throw Error('EEXIST')
}
} else if (errorOnExist) {
throw new Error(`${destFile} already exists`)
} else return
}
var fdr = fs.openSync(srcFile, 'r')
var stat = fs.fstatSync(fdr)
var fdw = fs.openSync(destFile, 'w', stat.mode)
var bytesRead = 1
var pos = 0
const fdr = fs.openSync(srcFile, 'r')
const stat = fs.fstatSync(fdr)
const fdw = fs.openSync(destFile, 'w', stat.mode)
let bytesRead = 1
let pos = 0
while (bytesRead > 0) {
bytesRead = fs.readSync(fdr, _buff, 0, BUF_LENGTH, pos)

View File

@@ -1,7 +1,9 @@
var fs = require('graceful-fs')
var path = require('path')
var copyFileSync = require('./copy-file-sync')
var mkdir = require('../mkdirs')
'use strict'
const fs = require('graceful-fs')
const path = require('path')
const copyFileSync = require('./copy-file-sync')
const mkdir = require('../mkdirs')
function copySync (src, dest, options) {
if (typeof options === 'function' || options instanceof RegExp) {
@@ -13,34 +15,46 @@ function copySync (src, dest, options) {
// default to true for now
options.clobber = 'clobber' in options ? !!options.clobber : true
// overwrite falls back to clobber
options.overwrite = 'overwrite' in options ? !!options.overwrite : options.clobber
options.dereference = 'dereference' in options ? !!options.dereference : false
options.preserveTimestamps = 'preserveTimestamps' in options ? !!options.preserveTimestamps : false
options.filter = options.filter || function () { return true }
var stats = (options.recursive && !options.dereference) ? fs.lstatSync(src) : fs.statSync(src)
var destFolder = path.dirname(dest)
var destFolderExists = fs.existsSync(destFolder)
var performCopy = false
// Warn about using preserveTimestamps on 32-bit node:
if (options.preserveTimestamps && process.arch === 'ia32') {
console.warn(`fs-extra: Using the preserveTimestamps option in 32-bit node is not recommended;\n
see https://github.com/jprichardson/node-fs-extra/issues/269`)
}
if (stats.isFile()) {
if (options.filter instanceof RegExp) performCopy = options.filter.test(src)
else if (typeof options.filter === 'function') performCopy = options.filter(src)
const stats = (options.recursive && !options.dereference) ? fs.lstatSync(src) : fs.statSync(src)
const destFolder = path.dirname(dest)
const destFolderExists = fs.existsSync(destFolder)
let performCopy = false
if (performCopy) {
if (!destFolderExists) mkdir.mkdirsSync(destFolder)
copyFileSync(src, dest, {clobber: options.clobber, preserveTimestamps: options.preserveTimestamps})
}
} else if (stats.isDirectory()) {
if (options.filter instanceof RegExp) {
console.warn('Warning: fs-extra: Passing a RegExp filter is deprecated, use a function')
performCopy = options.filter.test(src)
} else if (typeof options.filter === 'function') performCopy = options.filter(src, dest)
if (stats.isFile() && performCopy) {
if (!destFolderExists) mkdir.mkdirsSync(destFolder)
copyFileSync(src, dest, {
overwrite: options.overwrite,
errorOnExist: options.errorOnExist,
preserveTimestamps: options.preserveTimestamps
})
} else if (stats.isDirectory() && performCopy) {
if (!fs.existsSync(dest)) mkdir.mkdirsSync(dest)
var contents = fs.readdirSync(src)
contents.forEach(function (content) {
var opts = options
const contents = fs.readdirSync(src)
contents.forEach(content => {
const opts = options
opts.recursive = true
copySync(path.join(src, content), path.join(dest, content), opts)
})
} else if (options.recursive && stats.isSymbolicLink()) {
var srcPath = fs.readlinkSync(src)
} else if (options.recursive && stats.isSymbolicLink() && performCopy) {
const srcPath = fs.readlinkSync(src)
fs.symlinkSync(srcPath, dest)
}
}

View File

@@ -1,7 +1,10 @@
var fs = require('graceful-fs')
var path = require('path')
var ncp = require('./ncp')
var mkdir = require('../mkdirs')
'use strict'
const fs = require('graceful-fs')
const path = require('path')
const ncp = require('./ncp')
const mkdir = require('../mkdirs')
const pathExists = require('../path-exists').pathExists
function copy (src, dest, options, callback) {
if (typeof options === 'function' && !callback) {
@@ -13,27 +16,34 @@ function copy (src, dest, options, callback) {
callback = callback || function () {}
options = options || {}
// Warn about using preserveTimestamps on 32-bit node:
if (options.preserveTimestamps && process.arch === 'ia32') {
console.warn(`fs-extra: Using the preserveTimestamps option in 32-bit node is not recommended;\n
see https://github.com/jprichardson/node-fs-extra/issues/269`)
}
// don't allow src and dest to be the same
var basePath = process.cwd()
var currentPath = path.resolve(basePath, src)
var targetPath = path.resolve(basePath, dest)
const basePath = process.cwd()
const currentPath = path.resolve(basePath, src)
const targetPath = path.resolve(basePath, dest)
if (currentPath === targetPath) return callback(new Error('Source and destination must not be the same.'))
fs.lstat(src, function (err, stats) {
fs.lstat(src, (err, stats) => {
if (err) return callback(err)
var dir = null
let dir = null
if (stats.isDirectory()) {
var parts = dest.split(path.sep)
const parts = dest.split(path.sep)
parts.pop()
dir = parts.join(path.sep)
} else {
dir = path.dirname(dest)
}
fs.exists(dir, function (dirExists) {
pathExists(dir, (err, dirExists) => {
if (err) return callback(err)
if (dirExists) return ncp(src, dest, options, callback)
mkdir.mkdirs(dir, function (err) {
mkdir.mkdirs(dir, err => {
if (err) return callback(err)
ncp(src, dest, options, callback)
})

View File

@@ -1,3 +1,4 @@
const u = require('universalify').fromCallback
module.exports = {
copy: require('./copy')
copy: u(require('./copy'))
}

View File

@@ -16,18 +16,19 @@ function ncp (source, dest, options, callback) {
var filter = options.filter
var transform = options.transform
var clobber = options.clobber !== false
var overwrite = options.overwrite
// If overwrite is undefined, use clobber, otherwise default to true:
if (overwrite === undefined) overwrite = options.clobber
if (overwrite === undefined) overwrite = true
var errorOnExist = options.errorOnExist
var dereference = options.dereference
var preserveTimestamps = options.preserveTimestamps === true
var errs = null
var started = 0
var finished = 0
var running = 0
// this is pretty useless now that we're using graceful-fs
// consider removing
var limit = options.limit || 512
var errored = false
startCopy(currentPath)
@@ -35,11 +36,12 @@ function ncp (source, dest, options, callback) {
started++
if (filter) {
if (filter instanceof RegExp) {
console.warn('Warning: fs-extra: Passing a RegExp filter is deprecated, use a function')
if (!filter.test(source)) {
return doneOne(true)
}
} else if (typeof filter === 'function') {
if (!filter(source)) {
if (!filter(source, dest)) {
return doneOne(true)
}
}
@@ -49,11 +51,6 @@ function ncp (source, dest, options, callback) {
function getStats (source) {
var stat = dereference ? fs.stat : fs.lstat
if (running >= limit) {
return setImmediate(function () {
getStats(source)
})
}
running++
stat(source, function (err, stats) {
if (err) return onError(err)
@@ -79,15 +76,17 @@ function ncp (source, dest, options, callback) {
}
function onFile (file) {
var target = file.name.replace(currentPath, targetPath)
var target = file.name.replace(currentPath, targetPath.replace('$', '$$$$')) // escapes '$' with '$$'
isWritable(target, function (writable) {
if (writable) {
copyFile(file, target)
} else {
if (clobber) {
if (overwrite) {
rmFile(target, function () {
copyFile(file, target)
})
} else if (errorOnExist) {
onError(new Error(target + ' already exists'))
} else {
doneOne()
}
@@ -110,7 +109,7 @@ function ncp (source, dest, options, callback) {
})
}
writeStream.once('finish', function () {
writeStream.once('close', function () {
fs.chmod(target, file.mode, function (err) {
if (err) return onError(err)
if (preserveTimestamps) {
@@ -133,7 +132,7 @@ function ncp (source, dest, options, callback) {
}
function onDir (dir) {
var target = dir.name.replace(currentPath, targetPath)
var target = dir.name.replace(currentPath, targetPath.replace('$', '$$$$')) // escapes '$' with '$$'
isWritable(target, function (writable) {
if (writable) {
return mkDir(dir, target)
@@ -214,19 +213,11 @@ function ncp (source, dest, options, callback) {
}
function onError (err) {
if (options.stopOnError) {
// ensure callback is defined & called only once:
if (!errored && callback !== undefined) {
errored = true
return callback(err)
} else if (!errs && options.errs) {
errs = fs.createWriteStream(options.errs)
} else if (!errs) {
errs = []
}
if (typeof errs.write === 'undefined') {
errs.push(err)
} else {
errs.write(err.stack + '\n\n')
}
return doneOne()
}
function doneOne (skipped) {
@@ -234,7 +225,7 @@ function ncp (source, dest, options, callback) {
finished++
if ((started === finished) && (running === 0)) {
if (callback !== undefined) {
return errs ? callback(errs) : callback(null)
return callback(null)
}
}
}

View File

@@ -1,47 +1,48 @@
var fs = require('fs')
var path = require('path')
var mkdir = require('../mkdirs')
var remove = require('../remove')
'use strict'
function emptyDir (dir, callback) {
const u = require('universalify').fromCallback
const fs = require('fs')
const path = require('path')
const mkdir = require('../mkdirs')
const remove = require('../remove')
const emptyDir = u(function emptyDir (dir, callback) {
callback = callback || function () {}
fs.readdir(dir, function (err, items) {
fs.readdir(dir, (err, items) => {
if (err) return mkdir.mkdirs(dir, callback)
items = items.map(function (item) {
return path.join(dir, item)
})
items = items.map(item => path.join(dir, item))
deleteItem()
function deleteItem () {
var item = items.pop()
const item = items.pop()
if (!item) return callback()
remove.remove(item, function (err) {
remove.remove(item, err => {
if (err) return callback(err)
deleteItem()
})
}
})
}
})
function emptyDirSync (dir) {
var items
let items
try {
items = fs.readdirSync(dir)
} catch (err) {
return mkdir.mkdirsSync(dir)
}
items.forEach(function (item) {
items.forEach(item => {
item = path.join(dir, item)
remove.removeSync(item)
})
}
module.exports = {
emptyDirSync: emptyDirSync,
emptyDirSync,
emptydirSync: emptyDirSync,
emptyDir: emptyDir,
emptyDir,
emptydir: emptyDir
}

View File

@@ -1,21 +1,26 @@
var path = require('path')
var fs = require('graceful-fs')
var mkdir = require('../mkdirs')
'use strict'
const u = require('universalify').fromCallback
const path = require('path')
const fs = require('graceful-fs')
const mkdir = require('../mkdirs')
const pathExists = require('../path-exists').pathExists
function createFile (file, callback) {
function makeFile () {
fs.writeFile(file, '', function (err) {
fs.writeFile(file, '', err => {
if (err) return callback(err)
callback()
})
}
fs.exists(file, function (fileExists) {
if (fileExists) return callback()
var dir = path.dirname(file)
fs.exists(dir, function (dirExists) {
fs.stat(file, (err, stats) => { // eslint-disable-line handle-callback-err
if (!err && stats.isFile()) return callback()
const dir = path.dirname(file)
pathExists(dir, (err, dirExists) => {
if (err) return callback(err)
if (dirExists) return makeFile()
mkdir.mkdirs(dir, function (err) {
mkdir.mkdirs(dir, err => {
if (err) return callback(err)
makeFile()
})
@@ -24,9 +29,13 @@ function createFile (file, callback) {
}
function createFileSync (file) {
if (fs.existsSync(file)) return
let stats
try {
stats = fs.statSync(file)
} catch (e) {}
if (stats && stats.isFile()) return
var dir = path.dirname(file)
const dir = path.dirname(file)
if (!fs.existsSync(dir)) {
mkdir.mkdirsSync(dir)
}
@@ -35,9 +44,6 @@ function createFileSync (file) {
}
module.exports = {
createFile: createFile,
createFileSync: createFileSync,
// alias
ensureFile: createFile,
ensureFileSync: createFileSync
createFile: u(createFile),
createFileSync
}

View File

@@ -1,6 +1,8 @@
var file = require('./file')
var link = require('./link')
var symlink = require('./symlink')
'use strict'
const file = require('./file')
const link = require('./link')
const symlink = require('./symlink')
module.exports = {
// file

View File

@@ -1,27 +1,33 @@
var path = require('path')
var fs = require('graceful-fs')
var mkdir = require('../mkdirs')
'use strict'
const u = require('universalify').fromCallback
const path = require('path')
const fs = require('graceful-fs')
const mkdir = require('../mkdirs')
const pathExists = require('../path-exists').pathExists
function createLink (srcpath, dstpath, callback) {
function makeLink (srcpath, dstpath) {
fs.link(srcpath, dstpath, function (err) {
fs.link(srcpath, dstpath, err => {
if (err) return callback(err)
callback(null)
})
}
fs.exists(dstpath, function (destinationExists) {
pathExists(dstpath, (err, destinationExists) => {
if (err) return callback(err)
if (destinationExists) return callback(null)
fs.lstat(srcpath, function (err, stat) {
fs.lstat(srcpath, (err, stat) => {
if (err) {
err.message = err.message.replace('lstat', 'ensureLink')
return callback(err)
}
var dir = path.dirname(dstpath)
fs.exists(dir, function (dirExists) {
const dir = path.dirname(dstpath)
pathExists(dir, (err, dirExists) => {
if (err) return callback(err)
if (dirExists) return makeLink(srcpath, dstpath)
mkdir.mkdirs(dir, function (err) {
mkdir.mkdirs(dir, err => {
if (err) return callback(err)
makeLink(srcpath, dstpath)
})
@@ -31,7 +37,7 @@ function createLink (srcpath, dstpath, callback) {
}
function createLinkSync (srcpath, dstpath, callback) {
var destinationExists = fs.existsSync(dstpath)
const destinationExists = fs.existsSync(dstpath)
if (destinationExists) return undefined
try {
@@ -41,8 +47,8 @@ function createLinkSync (srcpath, dstpath, callback) {
throw err
}
var dir = path.dirname(dstpath)
var dirExists = fs.existsSync(dir)
const dir = path.dirname(dstpath)
const dirExists = fs.existsSync(dir)
if (dirExists) return fs.linkSync(srcpath, dstpath)
mkdir.mkdirsSync(dir)
@@ -50,9 +56,6 @@ function createLinkSync (srcpath, dstpath, callback) {
}
module.exports = {
createLink: createLink,
createLinkSync: createLinkSync,
// alias
ensureLink: createLink,
ensureLinkSync: createLinkSync
createLink: u(createLink),
createLinkSync
}

View File

@@ -1,7 +1,8 @@
var path = require('path')
// path.isAbsolute shim for Node.js 0.10 support
path.isAbsolute = (path.isAbsolute) ? path.isAbsolute : require('path-is-absolute')
var fs = require('graceful-fs')
'use strict'
const path = require('path')
const fs = require('graceful-fs')
const pathExists = require('../path-exists').pathExists
/**
* Function that returns two types of paths, one relative to symlink, and one
@@ -27,7 +28,7 @@ var fs = require('graceful-fs')
function symlinkPaths (srcpath, dstpath, callback) {
if (path.isAbsolute(srcpath)) {
return fs.lstat(srcpath, function (err, stat) {
return fs.lstat(srcpath, (err, stat) => {
if (err) {
err.message = err.message.replace('lstat', 'ensureSymlink')
return callback(err)
@@ -38,16 +39,17 @@ function symlinkPaths (srcpath, dstpath, callback) {
})
})
} else {
var dstdir = path.dirname(dstpath)
var relativeToDst = path.join(dstdir, srcpath)
return fs.exists(relativeToDst, function (exists) {
const dstdir = path.dirname(dstpath)
const relativeToDst = path.join(dstdir, srcpath)
return pathExists(relativeToDst, (err, exists) => {
if (err) return callback(err)
if (exists) {
return callback(null, {
'toCwd': relativeToDst,
'toDst': srcpath
})
} else {
return fs.lstat(srcpath, function (err, stat) {
return fs.lstat(srcpath, (err, stat) => {
if (err) {
err.message = err.message.replace('lstat', 'ensureSymlink')
return callback(err)
@@ -63,7 +65,7 @@ function symlinkPaths (srcpath, dstpath, callback) {
}
function symlinkPathsSync (srcpath, dstpath) {
var exists
let exists
if (path.isAbsolute(srcpath)) {
exists = fs.existsSync(srcpath)
if (!exists) throw new Error('absolute srcpath does not exist')
@@ -72,8 +74,8 @@ function symlinkPathsSync (srcpath, dstpath) {
'toDst': srcpath
}
} else {
var dstdir = path.dirname(dstpath)
var relativeToDst = path.join(dstdir, srcpath)
const dstdir = path.dirname(dstpath)
const relativeToDst = path.join(dstdir, srcpath)
exists = fs.existsSync(relativeToDst)
if (exists) {
return {
@@ -92,6 +94,6 @@ function symlinkPathsSync (srcpath, dstpath) {
}
module.exports = {
'symlinkPaths': symlinkPaths,
'symlinkPathsSync': symlinkPathsSync
symlinkPaths,
symlinkPathsSync
}

View File

@@ -1,10 +1,12 @@
var fs = require('graceful-fs')
'use strict'
const fs = require('graceful-fs')
function symlinkType (srcpath, type, callback) {
callback = (typeof type === 'function') ? type : callback
type = (typeof type === 'function') ? false : type
if (type) return callback(null, type)
fs.lstat(srcpath, function (err, stats) {
fs.lstat(srcpath, (err, stats) => {
if (err) return callback(null, 'file')
type = (stats && stats.isDirectory()) ? 'dir' : 'file'
callback(null, type)
@@ -12,9 +14,11 @@ function symlinkType (srcpath, type, callback) {
}
function symlinkTypeSync (srcpath, type) {
let stats
if (type) return type
try {
var stats = fs.lstatSync(srcpath)
stats = fs.lstatSync(srcpath)
} catch (e) {
return 'file'
}
@@ -22,6 +26,6 @@ function symlinkTypeSync (srcpath, type) {
}
module.exports = {
symlinkType: symlinkType,
symlinkTypeSync: symlinkTypeSync
symlinkType,
symlinkTypeSync
}

View File

@@ -1,32 +1,39 @@
var path = require('path')
var fs = require('graceful-fs')
var _mkdirs = require('../mkdirs')
var mkdirs = _mkdirs.mkdirs
var mkdirsSync = _mkdirs.mkdirsSync
'use strict'
var _symlinkPaths = require('./symlink-paths')
var symlinkPaths = _symlinkPaths.symlinkPaths
var symlinkPathsSync = _symlinkPaths.symlinkPathsSync
const u = require('universalify').fromCallback
const path = require('path')
const fs = require('graceful-fs')
const _mkdirs = require('../mkdirs')
const mkdirs = _mkdirs.mkdirs
const mkdirsSync = _mkdirs.mkdirsSync
var _symlinkType = require('./symlink-type')
var symlinkType = _symlinkType.symlinkType
var symlinkTypeSync = _symlinkType.symlinkTypeSync
const _symlinkPaths = require('./symlink-paths')
const symlinkPaths = _symlinkPaths.symlinkPaths
const symlinkPathsSync = _symlinkPaths.symlinkPathsSync
const _symlinkType = require('./symlink-type')
const symlinkType = _symlinkType.symlinkType
const symlinkTypeSync = _symlinkType.symlinkTypeSync
const pathExists = require('../path-exists').pathExists
function createSymlink (srcpath, dstpath, type, callback) {
callback = (typeof type === 'function') ? type : callback
type = (typeof type === 'function') ? false : type
fs.exists(dstpath, function (destinationExists) {
pathExists(dstpath, (err, destinationExists) => {
if (err) return callback(err)
if (destinationExists) return callback(null)
symlinkPaths(srcpath, dstpath, function (err, relative) {
symlinkPaths(srcpath, dstpath, (err, relative) => {
if (err) return callback(err)
srcpath = relative.toDst
symlinkType(relative.toCwd, type, function (err, type) {
symlinkType(relative.toCwd, type, (err, type) => {
if (err) return callback(err)
var dir = path.dirname(dstpath)
fs.exists(dir, function (dirExists) {
const dir = path.dirname(dstpath)
pathExists(dir, (err, dirExists) => {
if (err) return callback(err)
if (dirExists) return fs.symlink(srcpath, dstpath, type, callback)
mkdirs(dir, function (err) {
mkdirs(dir, err => {
if (err) return callback(err)
fs.symlink(srcpath, dstpath, type, callback)
})
@@ -40,23 +47,20 @@ function createSymlinkSync (srcpath, dstpath, type, callback) {
callback = (typeof type === 'function') ? type : callback
type = (typeof type === 'function') ? false : type
var destinationExists = fs.existsSync(dstpath)
const destinationExists = fs.existsSync(dstpath)
if (destinationExists) return undefined
var relative = symlinkPathsSync(srcpath, dstpath)
const relative = symlinkPathsSync(srcpath, dstpath)
srcpath = relative.toDst
type = symlinkTypeSync(relative.toCwd, type)
var dir = path.dirname(dstpath)
var exists = fs.existsSync(dir)
const dir = path.dirname(dstpath)
const exists = fs.existsSync(dir)
if (exists) return fs.symlinkSync(srcpath, dstpath, type)
mkdirsSync(dir)
return fs.symlinkSync(srcpath, dstpath, type)
}
module.exports = {
createSymlink: createSymlink,
createSymlinkSync: createSymlinkSync,
// alias
ensureSymlink: createSymlink,
ensureSymlinkSync: createSymlinkSync
createSymlink: u(createSymlink),
createSymlinkSync
}

107
app/node_modules/fs-extra/lib/fs/index.js generated vendored Normal file
View File

@@ -0,0 +1,107 @@
// This is adapted from https://github.com/normalize/mz
// Copyright (c) 2014-2016 Jonathan Ong me@jongleberry.com and Contributors
const u = require('universalify').fromCallback
const fs = require('graceful-fs')
const api = [
'access',
'appendFile',
'chmod',
'chown',
'close',
'copyFile',
'fchmod',
'fchown',
'fdatasync',
'fstat',
'fsync',
'ftruncate',
'futimes',
'lchown',
'link',
'lstat',
'mkdir',
'mkdtemp',
'open',
'readFile',
'readdir',
'readlink',
'realpath',
'rename',
'rmdir',
'stat',
'symlink',
'truncate',
'unlink',
'utimes',
'writeFile'
].filter(key => {
// Some commands are not available on some systems. Ex:
// fs.copyFile was added in Node.js v8.5.0
// fs.mkdtemp was added in Node.js v5.10.0
// fs.lchown is not available on at least some Linux
return typeof fs[key] === 'function'
})
// Export all keys:
Object.keys(fs).forEach(key => {
exports[key] = fs[key]
})
// Universalify async methods:
api.forEach(method => {
exports[method] = u(fs[method])
})
// We differ from mz/fs in that we still ship the old, broken, fs.exists()
// since we are a drop-in replacement for the native module
exports.exists = function (filename, callback) {
if (typeof callback === 'function') {
return fs.exists(filename, callback)
}
return new Promise(resolve => {
return fs.exists(filename, resolve)
})
}
// fs.read() & fs.write need special treatment due to multiple callback args
exports.read = function (fd, buffer, offset, length, position, callback) {
if (typeof callback === 'function') {
return fs.read(fd, buffer, offset, length, position, callback)
}
return new Promise((resolve, reject) => {
fs.read(fd, buffer, offset, length, position, (err, bytesRead, buffer) => {
if (err) return reject(err)
resolve({ bytesRead, buffer })
})
})
}
// Function signature can be
// fs.write(fd, buffer[, offset[, length[, position]]], callback)
// OR
// fs.write(fd, string[, position[, encoding]], callback)
// so we need to handle both cases
exports.write = function (fd, buffer, a, b, c, callback) {
if (typeof arguments[arguments.length - 1] === 'function') {
return fs.write(fd, buffer, a, b, c, callback)
}
// Check for old, depricated fs.write(fd, string[, position[, encoding]], callback)
if (typeof buffer === 'string') {
return new Promise((resolve, reject) => {
fs.write(fd, buffer, a, b, (err, bytesWritten, buffer) => {
if (err) return reject(err)
resolve({ bytesWritten, buffer })
})
})
}
return new Promise((resolve, reject) => {
fs.write(fd, buffer, a, b, c, (err, bytesWritten, buffer) => {
if (err) return reject(err)
resolve({ bytesWritten, buffer })
})
})
}

View File

@@ -1,37 +1,22 @@
var assign = require('./util/assign')
'use strict'
var fse = {}
var gfs = require('graceful-fs')
const assign = require('./util/assign')
// attach fs methods to fse
Object.keys(gfs).forEach(function (key) {
fse[key] = gfs[key]
})
var fs = fse
const fs = {}
// Export graceful-fs:
assign(fs, require('./fs'))
// Export extra methods:
assign(fs, require('./copy'))
assign(fs, require('./copy-sync'))
assign(fs, require('./mkdirs'))
assign(fs, require('./remove'))
assign(fs, require('./json'))
assign(fs, require('./move'))
assign(fs, require('./move-sync'))
assign(fs, require('./empty'))
assign(fs, require('./ensure'))
assign(fs, require('./output'))
assign(fs, require('./walk'))
assign(fs, require('./path-exists'))
module.exports = fs
// maintain backwards compatibility for awhile
var jsonfile = {}
Object.defineProperty(jsonfile, 'spaces', {
get: function () {
return fs.spaces // found in ./json
},
set: function (val) {
fs.spaces = val
}
})
module.exports.jsonfile = jsonfile // so users of fs-extra can modify jsonFile.spaces

View File

@@ -1,9 +1,16 @@
var jsonFile = require('./jsonfile')
'use strict'
const u = require('universalify').fromCallback
const jsonFile = require('./jsonfile')
jsonFile.outputJson = u(require('./output-json'))
jsonFile.outputJsonSync = require('./output-json-sync')
jsonFile.outputJson = require('./output-json')
// aliases
jsonFile.outputJSONSync = require('./output-json-sync')
jsonFile.outputJSON = require('./output-json')
jsonFile.outputJSON = jsonFile.outputJson
jsonFile.outputJSONSync = jsonFile.outputJsonSync
jsonFile.writeJSON = jsonFile.writeJson
jsonFile.writeJSONSync = jsonFile.writeJsonSync
jsonFile.readJSON = jsonFile.readJson
jsonFile.readJSONSync = jsonFile.readJsonSync
module.exports = jsonFile

View File

@@ -1,14 +1,12 @@
var jsonFile = require('jsonfile')
'use strict'
const u = require('universalify').fromCallback
const jsonFile = require('jsonfile')
module.exports = {
// jsonfile exports
readJson: jsonFile.readFile,
readJSON: jsonFile.readFile,
readJson: u(jsonFile.readFile),
readJsonSync: jsonFile.readFileSync,
readJSONSync: jsonFile.readFileSync,
writeJson: jsonFile.writeFile,
writeJSON: jsonFile.writeFile,
writeJsonSync: jsonFile.writeFileSync,
writeJSONSync: jsonFile.writeFileSync,
spaces: 2 // default in fs-extra
writeJson: u(jsonFile.writeFile),
writeJsonSync: jsonFile.writeFileSync
}

View File

@@ -1,10 +1,12 @@
var fs = require('graceful-fs')
var path = require('path')
var jsonFile = require('./jsonfile')
var mkdir = require('../mkdirs')
'use strict'
const fs = require('graceful-fs')
const path = require('path')
const mkdir = require('../mkdirs')
const jsonFile = require('./jsonfile')
function outputJsonSync (file, data, options) {
var dir = path.dirname(file)
const dir = path.dirname(file)
if (!fs.existsSync(dir)) {
mkdir.mkdirsSync(dir)

View File

@@ -1,7 +1,9 @@
var fs = require('graceful-fs')
var path = require('path')
var jsonFile = require('./jsonfile')
var mkdir = require('../mkdirs')
'use strict'
const path = require('path')
const mkdir = require('../mkdirs')
const pathExists = require('../path-exists').pathExists
const jsonFile = require('./jsonfile')
function outputJson (file, data, options, callback) {
if (typeof options === 'function') {
@@ -9,12 +11,13 @@ function outputJson (file, data, options, callback) {
options = {}
}
var dir = path.dirname(file)
const dir = path.dirname(file)
fs.exists(dir, function (itDoes) {
pathExists(dir, (err, itDoes) => {
if (err) return callback(err)
if (itDoes) return jsonFile.writeJson(file, data, options, callback)
mkdir.mkdirs(dir, function (err) {
mkdir.mkdirs(dir, err => {
if (err) return callback(err)
jsonFile.writeJson(file, data, options, callback)
})

View File

@@ -1,9 +1,14 @@
'use strict'
const u = require('universalify').fromCallback
const mkdirs = u(require('./mkdirs'))
const mkdirsSync = require('./mkdirs-sync')
module.exports = {
mkdirs: require('./mkdirs'),
mkdirsSync: require('./mkdirs-sync'),
mkdirs: mkdirs,
mkdirsSync: mkdirsSync,
// alias
mkdirp: require('./mkdirs'),
mkdirpSync: require('./mkdirs-sync'),
ensureDir: require('./mkdirs'),
ensureDirSync: require('./mkdirs-sync')
mkdirp: mkdirs,
mkdirpSync: mkdirsSync,
ensureDir: mkdirs,
ensureDirSync: mkdirsSync
}

View File

@@ -1,19 +1,21 @@
var fs = require('graceful-fs')
var path = require('path')
var invalidWin32Path = require('./win32').invalidWin32Path
'use strict'
var o777 = parseInt('0777', 8)
const fs = require('graceful-fs')
const path = require('path')
const invalidWin32Path = require('./win32').invalidWin32Path
const o777 = parseInt('0777', 8)
function mkdirsSync (p, opts, made) {
if (!opts || typeof opts !== 'object') {
opts = { mode: opts }
}
var mode = opts.mode
var xfs = opts.fs || fs
let mode = opts.mode
const xfs = opts.fs || fs
if (process.platform === 'win32' && invalidWin32Path(p)) {
var errInval = new Error(p + ' contains invalid WIN32 path characters.')
const errInval = new Error(p + ' contains invalid WIN32 path characters.')
errInval.code = 'EINVAL'
throw errInval
}
@@ -40,7 +42,7 @@ function mkdirsSync (p, opts, made) {
// there already. If so, then hooray! If not, then something
// is borked.
default:
var stat
let stat
try {
stat = xfs.statSync(p)
} catch (err1) {

View File

@@ -1,8 +1,10 @@
var fs = require('graceful-fs')
var path = require('path')
var invalidWin32Path = require('./win32').invalidWin32Path
'use strict'
var o777 = parseInt('0777', 8)
const fs = require('graceful-fs')
const path = require('path')
const invalidWin32Path = require('./win32').invalidWin32Path
const o777 = parseInt('0777', 8)
function mkdirs (p, opts, callback, made) {
if (typeof opts === 'function') {
@@ -13,13 +15,13 @@ function mkdirs (p, opts, callback, made) {
}
if (process.platform === 'win32' && invalidWin32Path(p)) {
var errInval = new Error(p + ' contains invalid WIN32 path characters.')
const errInval = new Error(p + ' contains invalid WIN32 path characters.')
errInval.code = 'EINVAL'
return callback(errInval)
}
var mode = opts.mode
var xfs = opts.fs || fs
let mode = opts.mode
const xfs = opts.fs || fs
if (mode === undefined) {
mode = o777 & (~process.umask())
@@ -29,7 +31,7 @@ function mkdirs (p, opts, callback, made) {
callback = callback || function () {}
p = path.resolve(p)
xfs.mkdir(p, mode, function (er) {
xfs.mkdir(p, mode, er => {
if (!er) {
made = made || p
return callback(null, made)
@@ -37,7 +39,7 @@ function mkdirs (p, opts, callback, made) {
switch (er.code) {
case 'ENOENT':
if (path.dirname(p) === p) return callback(er)
mkdirs(path.dirname(p), opts, function (er, made) {
mkdirs(path.dirname(p), opts, (er, made) => {
if (er) callback(er, made)
else mkdirs(p, opts, callback, made)
})
@@ -47,7 +49,7 @@ function mkdirs (p, opts, callback, made) {
// there already. If so, then hooray! If not, then something
// is borked.
default:
xfs.stat(p, function (er2, stat) {
xfs.stat(p, (er2, stat) => {
// if the stat fails, then that's super weird.
// let the original error be the failure reason.
if (er2 || !stat.isDirectory()) callback(er, made)

View File

@@ -1,24 +1,25 @@
'use strict'
var path = require('path')
const path = require('path')
// get drive on windows
function getRootPath (p) {
p = path.normalize(path.resolve(p)).split(path.sep)
if (p.length > 0) return p[0]
else return null
return null
}
// http://stackoverflow.com/a/62888/10333 contains more accurate
// TODO: expand to include the rest
var INVALID_PATH_CHARS = /[<>:"|?*]/
const INVALID_PATH_CHARS = /[<>:"|?*]/
function invalidWin32Path (p) {
var rp = getRootPath(p)
const rp = getRootPath(p)
p = p.replace(rp, '')
return INVALID_PATH_CHARS.test(p)
}
module.exports = {
getRootPath: getRootPath,
invalidWin32Path: invalidWin32Path
getRootPath,
invalidWin32Path
}

118
app/node_modules/fs-extra/lib/move-sync/index.js generated vendored Normal file
View File

@@ -0,0 +1,118 @@
'use strict'
const fs = require('graceful-fs')
const path = require('path')
const copySync = require('../copy-sync').copySync
const removeSync = require('../remove').removeSync
const mkdirpSync = require('../mkdirs').mkdirsSync
const buffer = require('../util/buffer')
function moveSync (src, dest, options) {
options = options || {}
const overwrite = options.overwrite || options.clobber || false
src = path.resolve(src)
dest = path.resolve(dest)
if (src === dest) return fs.accessSync(src)
if (isSrcSubdir(src, dest)) throw new Error(`Cannot move '${src}' into itself '${dest}'.`)
mkdirpSync(path.dirname(dest))
tryRenameSync()
function tryRenameSync () {
if (overwrite) {
try {
return fs.renameSync(src, dest)
} catch (err) {
if (err.code === 'ENOTEMPTY' || err.code === 'EEXIST' || err.code === 'EPERM') {
removeSync(dest)
options.overwrite = false // just overwriteed it, no need to do it again
return moveSync(src, dest, options)
}
if (err.code !== 'EXDEV') throw err
return moveSyncAcrossDevice(src, dest, overwrite)
}
} else {
try {
fs.linkSync(src, dest)
return fs.unlinkSync(src)
} catch (err) {
if (err.code === 'EXDEV' || err.code === 'EISDIR' || err.code === 'EPERM' || err.code === 'ENOTSUP') {
return moveSyncAcrossDevice(src, dest, overwrite)
}
throw err
}
}
}
}
function moveSyncAcrossDevice (src, dest, overwrite) {
const stat = fs.statSync(src)
if (stat.isDirectory()) {
return moveDirSyncAcrossDevice(src, dest, overwrite)
} else {
return moveFileSyncAcrossDevice(src, dest, overwrite)
}
}
function moveFileSyncAcrossDevice (src, dest, overwrite) {
const BUF_LENGTH = 64 * 1024
const _buff = buffer(BUF_LENGTH)
const flags = overwrite ? 'w' : 'wx'
const fdr = fs.openSync(src, 'r')
const stat = fs.fstatSync(fdr)
const fdw = fs.openSync(dest, flags, stat.mode)
let bytesRead = 1
let pos = 0
while (bytesRead > 0) {
bytesRead = fs.readSync(fdr, _buff, 0, BUF_LENGTH, pos)
fs.writeSync(fdw, _buff, 0, bytesRead)
pos += bytesRead
}
fs.closeSync(fdr)
fs.closeSync(fdw)
return fs.unlinkSync(src)
}
function moveDirSyncAcrossDevice (src, dest, overwrite) {
const options = {
overwrite: false
}
if (overwrite) {
removeSync(dest)
tryCopySync()
} else {
tryCopySync()
}
function tryCopySync () {
copySync(src, dest, options)
return removeSync(src)
}
}
// return true if dest is a subdir of src, otherwise false.
// extract dest base dir and check if that is the same as src basename
function isSrcSubdir (src, dest) {
try {
return fs.statSync(src).isDirectory() &&
src !== dest &&
dest.indexOf(src) > -1 &&
dest.split(path.dirname(src) + path.sep)[1].split(path.sep)[0] === path.basename(src)
} catch (e) {
return false
}
}
module.exports = {
moveSync
}

View File

@@ -1,105 +1,98 @@
'use strict'
// most of this code was written by Andrew Kelley
// licensed under the BSD license: see
// https://github.com/andrewrk/node-mv/blob/master/package.json
// this needs a cleanup
var fs = require('graceful-fs')
var ncp = require('../copy/ncp')
var path = require('path')
var rimraf = require('rimraf')
var mkdirp = require('../mkdirs').mkdirs
const u = require('universalify').fromCallback
const fs = require('graceful-fs')
const ncp = require('../copy/ncp')
const path = require('path')
const remove = require('../remove').remove
const mkdirp = require('../mkdirs').mkdirs
function mv (source, dest, options, callback) {
function move (src, dest, options, callback) {
if (typeof options === 'function') {
callback = options
options = {}
}
var shouldMkdirp = ('mkdirp' in options) ? options.mkdirp : true
var clobber = ('clobber' in options) ? options.clobber : false
const overwrite = options.overwrite || options.clobber || false
var limit = options.limit || 16
if (shouldMkdirp) {
mkdirs()
} else {
doRename()
}
function mkdirs () {
mkdirp(path.dirname(dest), function (err) {
isSrcSubdir(src, dest, (err, itIs) => {
if (err) return callback(err)
if (itIs) return callback(new Error(`Cannot move '${src}' to a subdirectory of itself, '${dest}'.`))
mkdirp(path.dirname(dest), err => {
if (err) return callback(err)
doRename()
})
}
})
function doRename () {
if (clobber) {
fs.rename(source, dest, function (err) {
if (path.resolve(src) === path.resolve(dest)) {
fs.access(src, callback)
} else if (overwrite) {
fs.rename(src, dest, err => {
if (!err) return callback()
if (err.code === 'ENOTEMPTY' || err.code === 'EEXIST') {
rimraf(dest, function (err) {
remove(dest, err => {
if (err) return callback(err)
options.clobber = false // just clobbered it, no need to do it again
mv(source, dest, options, callback)
options.overwrite = false // just overwriteed it, no need to do it again
move(src, dest, options, callback)
})
return
}
// weird Windows shit
if (err.code === 'EPERM') {
setTimeout(function () {
rimraf(dest, function (err) {
setTimeout(() => {
remove(dest, err => {
if (err) return callback(err)
options.clobber = false
mv(source, dest, options, callback)
options.overwrite = false
move(src, dest, options, callback)
})
}, 200)
return
}
if (err.code !== 'EXDEV') return callback(err)
moveAcrossDevice(source, dest, clobber, limit, callback)
moveAcrossDevice(src, dest, overwrite, callback)
})
} else {
fs.link(source, dest, function (err) {
fs.link(src, dest, err => {
if (err) {
if (err.code === 'EXDEV' || err.code === 'EISDIR' || err.code === 'EPERM') {
moveAcrossDevice(source, dest, clobber, limit, callback)
return
if (err.code === 'EXDEV' || err.code === 'EISDIR' || err.code === 'EPERM' || err.code === 'ENOTSUP') {
return moveAcrossDevice(src, dest, overwrite, callback)
}
callback(err)
return
return callback(err)
}
fs.unlink(source, callback)
return fs.unlink(src, callback)
})
}
}
}
function moveAcrossDevice (source, dest, clobber, limit, callback) {
fs.stat(source, function (err, stat) {
if (err) {
callback(err)
return
}
function moveAcrossDevice (src, dest, overwrite, callback) {
fs.stat(src, (err, stat) => {
if (err) return callback(err)
if (stat.isDirectory()) {
moveDirAcrossDevice(source, dest, clobber, limit, callback)
moveDirAcrossDevice(src, dest, overwrite, callback)
} else {
moveFileAcrossDevice(source, dest, clobber, limit, callback)
moveFileAcrossDevice(src, dest, overwrite, callback)
}
})
}
function moveFileAcrossDevice (source, dest, clobber, limit, callback) {
var outFlags = clobber ? 'w' : 'wx'
var ins = fs.createReadStream(source)
var outs = fs.createWriteStream(dest, {flags: outFlags})
function moveFileAcrossDevice (src, dest, overwrite, callback) {
const flags = overwrite ? 'w' : 'wx'
const ins = fs.createReadStream(src)
const outs = fs.createWriteStream(dest, { flags })
ins.on('error', function (err) {
ins.on('error', err => {
ins.destroy()
outs.destroy()
outs.removeListener('close', onClose)
@@ -107,17 +100,17 @@ function moveFileAcrossDevice (source, dest, clobber, limit, callback) {
// may want to create a directory but `out` line above
// creates an empty file for us: See #108
// don't care about error here
fs.unlink(dest, function () {
fs.unlink(dest, () => {
// note: `err` here is from the input stream errror
if (err.code === 'EISDIR' || err.code === 'EPERM') {
moveDirAcrossDevice(source, dest, clobber, limit, callback)
moveDirAcrossDevice(src, dest, overwrite, callback)
} else {
callback(err)
}
})
})
outs.on('error', function (err) {
outs.on('error', err => {
ins.destroy()
outs.destroy()
outs.removeListener('close', onClose)
@@ -128,34 +121,50 @@ function moveFileAcrossDevice (source, dest, clobber, limit, callback) {
ins.pipe(outs)
function onClose () {
fs.unlink(source, callback)
fs.unlink(src, callback)
}
}
function moveDirAcrossDevice (source, dest, clobber, limit, callback) {
var options = {
stopOnErr: true,
clobber: false,
limit: limit
function moveDirAcrossDevice (src, dest, overwrite, callback) {
const options = {
overwrite: false
}
function startNcp () {
ncp(source, dest, options, function (errList) {
if (errList) return callback(errList[0])
rimraf(source, callback)
})
}
if (clobber) {
rimraf(dest, function (err) {
if (overwrite) {
remove(dest, err => {
if (err) return callback(err)
startNcp()
})
} else {
startNcp()
}
function startNcp () {
ncp(src, dest, options, err => {
if (err) return callback(err)
remove(src, callback)
})
}
}
// return true if dest is a subdir of src, otherwise false.
// extract dest base dir and check if that is the same as src basename
function isSrcSubdir (src, dest, cb) {
fs.stat(src, (err, st) => {
if (err) return cb(err)
if (st.isDirectory()) {
const baseDir = dest.split(path.dirname(src) + path.sep)[1]
if (baseDir) {
const destBasename = baseDir.split(path.sep)[0]
if (destBasename) return cb(null, src !== dest && dest.indexOf(src) > -1 && destBasename === path.basename(src))
return cb(null, false)
}
return cb(null, false)
}
return cb(null, false)
})
}
module.exports = {
move: mv
move: u(move)
}

View File

@@ -1,6 +1,10 @@
var path = require('path')
var fs = require('graceful-fs')
var mkdir = require('../mkdirs')
'use strict'
const u = require('universalify').fromCallback
const fs = require('graceful-fs')
const path = require('path')
const mkdir = require('../mkdirs')
const pathExists = require('../path-exists').pathExists
function outputFile (file, data, encoding, callback) {
if (typeof encoding === 'function') {
@@ -8,11 +12,12 @@ function outputFile (file, data, encoding, callback) {
encoding = 'utf8'
}
var dir = path.dirname(file)
fs.exists(dir, function (itDoes) {
const dir = path.dirname(file)
pathExists(dir, (err, itDoes) => {
if (err) return callback(err)
if (itDoes) return fs.writeFile(file, data, encoding, callback)
mkdir.mkdirs(dir, function (err) {
mkdir.mkdirs(dir, err => {
if (err) return callback(err)
fs.writeFile(file, data, encoding, callback)
@@ -21,7 +26,7 @@ function outputFile (file, data, encoding, callback) {
}
function outputFileSync (file, data, encoding) {
var dir = path.dirname(file)
const dir = path.dirname(file)
if (fs.existsSync(dir)) {
return fs.writeFileSync.apply(fs, arguments)
}
@@ -30,6 +35,6 @@ function outputFileSync (file, data, encoding) {
}
module.exports = {
outputFile: outputFile,
outputFileSync: outputFileSync
outputFile: u(outputFile),
outputFileSync
}

12
app/node_modules/fs-extra/lib/path-exists/index.js generated vendored Normal file
View File

@@ -0,0 +1,12 @@
'use strict'
const u = require('universalify').fromPromise
const fs = require('../fs')
function pathExists (path) {
return fs.access(path).then(() => true).catch(() => false)
}
module.exports = {
pathExists: u(pathExists),
pathExistsSync: fs.existsSync
}

View File

@@ -1,14 +1,9 @@
var rimraf = require('rimraf')
'use strict'
function removeSync (dir) {
return rimraf.sync(dir)
}
function remove (dir, callback) {
return callback ? rimraf(dir, callback) : rimraf(dir, function () {})
}
const u = require('universalify').fromCallback
const rimraf = require('./rimraf')
module.exports = {
remove: remove,
removeSync: removeSync
remove: u(rimraf),
removeSync: rimraf.sync
}

314
app/node_modules/fs-extra/lib/remove/rimraf.js generated vendored Normal file
View File

@@ -0,0 +1,314 @@
'use strict'
const fs = require('graceful-fs')
const path = require('path')
const assert = require('assert')
const isWindows = (process.platform === 'win32')
function defaults (options) {
const methods = [
'unlink',
'chmod',
'stat',
'lstat',
'rmdir',
'readdir'
]
methods.forEach(m => {
options[m] = options[m] || fs[m]
m = m + 'Sync'
options[m] = options[m] || fs[m]
})
options.maxBusyTries = options.maxBusyTries || 3
}
function rimraf (p, options, cb) {
let busyTries = 0
if (typeof options === 'function') {
cb = options
options = {}
}
assert(p, 'rimraf: missing path')
assert.equal(typeof p, 'string', 'rimraf: path should be a string')
assert.equal(typeof cb, 'function', 'rimraf: callback function required')
assert(options, 'rimraf: invalid options argument provided')
assert.equal(typeof options, 'object', 'rimraf: options should be object')
defaults(options)
rimraf_(p, options, function CB (er) {
if (er) {
if ((er.code === 'EBUSY' || er.code === 'ENOTEMPTY' || er.code === 'EPERM') &&
busyTries < options.maxBusyTries) {
busyTries++
let time = busyTries * 100
// try again, with the same exact callback as this one.
return setTimeout(() => rimraf_(p, options, CB), time)
}
// already gone
if (er.code === 'ENOENT') er = null
}
cb(er)
})
}
// Two possible strategies.
// 1. Assume it's a file. unlink it, then do the dir stuff on EPERM or EISDIR
// 2. Assume it's a directory. readdir, then do the file stuff on ENOTDIR
//
// Both result in an extra syscall when you guess wrong. However, there
// are likely far more normal files in the world than directories. This
// is based on the assumption that a the average number of files per
// directory is >= 1.
//
// If anyone ever complains about this, then I guess the strategy could
// be made configurable somehow. But until then, YAGNI.
function rimraf_ (p, options, cb) {
assert(p)
assert(options)
assert(typeof cb === 'function')
// sunos lets the root user unlink directories, which is... weird.
// so we have to lstat here and make sure it's not a dir.
options.lstat(p, (er, st) => {
if (er && er.code === 'ENOENT') {
return cb(null)
}
// Windows can EPERM on stat. Life is suffering.
if (er && er.code === 'EPERM' && isWindows) {
return fixWinEPERM(p, options, er, cb)
}
if (st && st.isDirectory()) {
return rmdir(p, options, er, cb)
}
options.unlink(p, er => {
if (er) {
if (er.code === 'ENOENT') {
return cb(null)
}
if (er.code === 'EPERM') {
return (isWindows)
? fixWinEPERM(p, options, er, cb)
: rmdir(p, options, er, cb)
}
if (er.code === 'EISDIR') {
return rmdir(p, options, er, cb)
}
}
return cb(er)
})
})
}
function fixWinEPERM (p, options, er, cb) {
assert(p)
assert(options)
assert(typeof cb === 'function')
if (er) {
assert(er instanceof Error)
}
options.chmod(p, 0o666, er2 => {
if (er2) {
cb(er2.code === 'ENOENT' ? null : er)
} else {
options.stat(p, (er3, stats) => {
if (er3) {
cb(er3.code === 'ENOENT' ? null : er)
} else if (stats.isDirectory()) {
rmdir(p, options, er, cb)
} else {
options.unlink(p, cb)
}
})
}
})
}
function fixWinEPERMSync (p, options, er) {
let stats
assert(p)
assert(options)
if (er) {
assert(er instanceof Error)
}
try {
options.chmodSync(p, 0o666)
} catch (er2) {
if (er2.code === 'ENOENT') {
return
} else {
throw er
}
}
try {
stats = options.statSync(p)
} catch (er3) {
if (er3.code === 'ENOENT') {
return
} else {
throw er
}
}
if (stats.isDirectory()) {
rmdirSync(p, options, er)
} else {
options.unlinkSync(p)
}
}
function rmdir (p, options, originalEr, cb) {
assert(p)
assert(options)
if (originalEr) {
assert(originalEr instanceof Error)
}
assert(typeof cb === 'function')
// try to rmdir first, and only readdir on ENOTEMPTY or EEXIST (SunOS)
// if we guessed wrong, and it's not a directory, then
// raise the original error.
options.rmdir(p, er => {
if (er && (er.code === 'ENOTEMPTY' || er.code === 'EEXIST' || er.code === 'EPERM')) {
rmkids(p, options, cb)
} else if (er && er.code === 'ENOTDIR') {
cb(originalEr)
} else {
cb(er)
}
})
}
function rmkids (p, options, cb) {
assert(p)
assert(options)
assert(typeof cb === 'function')
options.readdir(p, (er, files) => {
if (er) return cb(er)
let n = files.length
let errState
if (n === 0) return options.rmdir(p, cb)
files.forEach(f => {
rimraf(path.join(p, f), options, er => {
if (errState) {
return
}
if (er) return cb(errState = er)
if (--n === 0) {
options.rmdir(p, cb)
}
})
})
})
}
// this looks simpler, and is strictly *faster*, but will
// tie up the JavaScript thread and fail on excessively
// deep directory trees.
function rimrafSync (p, options) {
let st
options = options || {}
defaults(options)
assert(p, 'rimraf: missing path')
assert.equal(typeof p, 'string', 'rimraf: path should be a string')
assert(options, 'rimraf: missing options')
assert.equal(typeof options, 'object', 'rimraf: options should be object')
try {
st = options.lstatSync(p)
} catch (er) {
if (er.code === 'ENOENT') {
return
}
// Windows can EPERM on stat. Life is suffering.
if (er.code === 'EPERM' && isWindows) {
fixWinEPERMSync(p, options, er)
}
}
try {
// sunos lets the root user unlink directories, which is... weird.
if (st && st.isDirectory()) {
rmdirSync(p, options, null)
} else {
options.unlinkSync(p)
}
} catch (er) {
if (er.code === 'ENOENT') {
return
} else if (er.code === 'EPERM') {
return isWindows ? fixWinEPERMSync(p, options, er) : rmdirSync(p, options, er)
} else if (er.code !== 'EISDIR') {
throw er
}
rmdirSync(p, options, er)
}
}
function rmdirSync (p, options, originalEr) {
assert(p)
assert(options)
if (originalEr) {
assert(originalEr instanceof Error)
}
try {
options.rmdirSync(p)
} catch (er) {
if (er.code === 'ENOTDIR') {
throw originalEr
} else if (er.code === 'ENOTEMPTY' || er.code === 'EEXIST' || er.code === 'EPERM') {
rmkidsSync(p, options)
} else if (er.code !== 'ENOENT') {
throw er
}
}
}
function rmkidsSync (p, options) {
assert(p)
assert(options)
options.readdirSync(p).forEach(f => rimrafSync(path.join(p, f), options))
// We only end up here once we got ENOTEMPTY at least once, and
// at this point, we are guaranteed to have removed all the kids.
// So, we know that it won't be ENOENT or ENOTDIR or anything else.
// try really hard to delete stuff on windows, because it has a
// PROFOUNDLY annoying habit of not closing handles promptly when
// files are deleted, resulting in spurious ENOTEMPTY errors.
const retries = isWindows ? 100 : 1
let i = 0
do {
let threw = true
try {
const ret = options.rmdirSync(p, options)
threw = false
return ret
} finally {
if (++i < retries && threw) continue // eslint-disable-line
}
} while (true)
}
module.exports = rimraf
rimraf.sync = rimrafSync

View File

@@ -1,9 +1,11 @@
'use strict'
// simple mutable assign
function assign () {
var args = [].slice.call(arguments).filter(function (i) { return i })
var dest = args.shift()
args.forEach(function (src) {
Object.keys(src).forEach(function (key) {
const args = [].slice.call(arguments).filter(i => i)
const dest = args.shift()
args.forEach(src => {
Object.keys(src).forEach(key => {
dest[key] = src[key]
})
})

11
app/node_modules/fs-extra/lib/util/buffer.js generated vendored Normal file
View File

@@ -0,0 +1,11 @@
/* 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)
}

View File

@@ -1,36 +1,38 @@
var fs = require('graceful-fs')
var path = require('path')
var os = require('os')
'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 () {
var tmpfile = path.join('millis-test-sync' + Date.now().toString() + Math.random().toString().slice(2))
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
var d = new Date(1435410243862)
const d = new Date(1435410243862)
fs.writeFileSync(tmpfile, 'https://github.com/jprichardson/node-fs-extra/pull/141')
var fd = fs.openSync(tmpfile, 'r+')
const fd = fs.openSync(tmpfile, 'r+')
fs.futimesSync(fd, d, d)
fs.closeSync(fd)
return fs.statSync(tmpfile).mtime > 1435410243000
}
function hasMillisRes (callback) {
var tmpfile = path.join('millis-test' + Date.now().toString() + Math.random().toString().slice(2))
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
var d = new Date(1435410243862)
fs.writeFile(tmpfile, 'https://github.com/jprichardson/node-fs-extra/pull/141', function (err) {
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+', function (err, fd) {
fs.open(tmpfile, 'r+', (err, fd) => {
if (err) return callback(err)
fs.futimes(fd, d, d, function (err) {
fs.futimes(fd, d, d, err => {
if (err) return callback(err)
fs.close(fd, function (err) {
fs.close(fd, err => {
if (err) return callback(err)
fs.stat(tmpfile, function (err, stats) {
fs.stat(tmpfile, (err, stats) => {
if (err) return callback(err)
callback(null, stats.mtime > 1435410243000)
})
@@ -52,18 +54,19 @@ function timeRemoveMillis (timestamp) {
function utimesMillis (path, atime, mtime, callback) {
// if (!HAS_MILLIS_RES) return fs.utimes(path, atime, mtime, callback)
fs.open(path, 'r+', function (err, fd) {
fs.open(path, 'r+', (err, fd) => {
if (err) return callback(err)
fs.futimes(fd, atime, mtime, function (err) {
if (err) return callback(err)
fs.close(fd, callback)
fs.futimes(fd, atime, mtime, futimesErr => {
fs.close(fd, closeErr => {
if (callback) callback(futimesErr || closeErr)
})
})
})
}
module.exports = {
hasMillisRes: hasMillisRes,
hasMillisResSync: hasMillisResSync,
timeRemoveMillis: timeRemoveMillis,
utimesMillis: utimesMillis
hasMillisRes,
hasMillisResSync,
timeRemoveMillis,
utimesMillis
}

View File

@@ -1,5 +0,0 @@
var klaw = require('klaw')
module.exports = {
walk: klaw
}