aboutsummaryrefslogtreecommitdiff
path: root/node_modules/fs-extra/lib/copy
diff options
context:
space:
mode:
authorPriyansh <[email protected]>2020-12-22 17:50:12 +0530
committerPriyansh <[email protected]>2020-12-22 17:50:12 +0530
commit22dc033f4938d6a19e086a1cbd36ec5cade5eaab (patch)
tree9feb963ccd5c1581e676e41004801abc67db3357 /node_modules/fs-extra/lib/copy
parente93da8b04da86773247aadb1cbb1912e4f4526b2 (diff)
downloadstyx-22dc033f4938d6a19e086a1cbd36ec5cade5eaab.tar.xz
styx-22dc033f4938d6a19e086a1cbd36ec5cade5eaab.zip
Remove node_modules
Diffstat (limited to 'node_modules/fs-extra/lib/copy')
-rw-r--r--node_modules/fs-extra/lib/copy/copy.js212
-rw-r--r--node_modules/fs-extra/lib/copy/index.js6
2 files changed, 0 insertions, 218 deletions
diff --git a/node_modules/fs-extra/lib/copy/copy.js b/node_modules/fs-extra/lib/copy/copy.js
deleted file mode 100644
index 411fc64..0000000
--- a/node_modules/fs-extra/lib/copy/copy.js
+++ /dev/null
@@ -1,212 +0,0 @@
-'use strict'
-
-const fs = require('graceful-fs')
-const path = require('path')
-const mkdirp = require('../mkdirs').mkdirs
-const pathExists = require('../path-exists').pathExists
-const utimes = require('../util/utimes').utimesMillis
-const stat = require('../util/stat')
-
-function copy (src, dest, opts, cb) {
- if (typeof opts === 'function' && !cb) {
- cb = opts
- opts = {}
- } else if (typeof opts === 'function') {
- opts = { filter: opts }
- }
-
- cb = cb || function () {}
- opts = opts || {}
-
- opts.clobber = 'clobber' in opts ? !!opts.clobber : true // default to true for now
- opts.overwrite = 'overwrite' in opts ? !!opts.overwrite : opts.clobber // overwrite falls back to clobber
-
- // Warn about using preserveTimestamps on 32-bit node
- if (opts.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`)
- }
-
- stat.checkPaths(src, dest, 'copy', (err, stats) => {
- if (err) return cb(err)
- const { srcStat, destStat } = stats
- stat.checkParentPaths(src, srcStat, dest, 'copy', err => {
- if (err) return cb(err)
- if (opts.filter) return handleFilter(checkParentDir, destStat, src, dest, opts, cb)
- return checkParentDir(destStat, src, dest, opts, cb)
- })
- })
-}
-
-function checkParentDir (destStat, src, dest, opts, cb) {
- const destParent = path.dirname(dest)
- pathExists(destParent, (err, dirExists) => {
- if (err) return cb(err)
- if (dirExists) return startCopy(destStat, src, dest, opts, cb)
- mkdirp(destParent, err => {
- if (err) return cb(err)
- return startCopy(destStat, src, dest, opts, cb)
- })
- })
-}
-
-function handleFilter (onInclude, destStat, src, dest, opts, cb) {
- Promise.resolve(opts.filter(src, dest)).then(include => {
- if (include) return onInclude(destStat, src, dest, opts, cb)
- return cb()
- }, error => cb(error))
-}
-
-function startCopy (destStat, src, dest, opts, cb) {
- if (opts.filter) return handleFilter(getStats, destStat, src, dest, opts, cb)
- return getStats(destStat, src, dest, opts, cb)
-}
-
-function getStats (destStat, src, dest, opts, cb) {
- const stat = opts.dereference ? fs.stat : fs.lstat
- stat(src, (err, srcStat) => {
- if (err) return cb(err)
-
- if (srcStat.isDirectory()) return onDir(srcStat, destStat, src, dest, opts, cb)
- else if (srcStat.isFile() ||
- srcStat.isCharacterDevice() ||
- srcStat.isBlockDevice()) return onFile(srcStat, destStat, src, dest, opts, cb)
- else if (srcStat.isSymbolicLink()) return onLink(destStat, src, dest, opts, cb)
- })
-}
-
-function onFile (srcStat, destStat, src, dest, opts, cb) {
- if (!destStat) return copyFile(srcStat, src, dest, opts, cb)
- return mayCopyFile(srcStat, src, dest, opts, cb)
-}
-
-function mayCopyFile (srcStat, src, dest, opts, cb) {
- if (opts.overwrite) {
- fs.unlink(dest, err => {
- if (err) return cb(err)
- return copyFile(srcStat, src, dest, opts, cb)
- })
- } else if (opts.errorOnExist) {
- return cb(new Error(`'${dest}' already exists`))
- } else return cb()
-}
-
-function copyFile (srcStat, src, dest, opts, cb) {
- if (typeof fs.copyFile === 'function') {
- return fs.copyFile(src, dest, err => {
- if (err) return cb(err)
- return setDestModeAndTimestamps(srcStat, dest, opts, cb)
- })
- }
- return copyFileFallback(srcStat, src, dest, opts, cb)
-}
-
-function copyFileFallback (srcStat, src, dest, opts, cb) {
- const rs = fs.createReadStream(src)
- rs.on('error', err => cb(err)).once('open', () => {
- const ws = fs.createWriteStream(dest, { mode: srcStat.mode })
- ws.on('error', err => cb(err))
- .on('open', () => rs.pipe(ws))
- .once('close', () => setDestModeAndTimestamps(srcStat, dest, opts, cb))
- })
-}
-
-function setDestModeAndTimestamps (srcStat, dest, opts, cb) {
- fs.chmod(dest, srcStat.mode, err => {
- if (err) return cb(err)
- if (opts.preserveTimestamps) {
- return utimes(dest, srcStat.atime, srcStat.mtime, cb)
- }
- return cb()
- })
-}
-
-function onDir (srcStat, destStat, src, dest, opts, cb) {
- if (!destStat) return mkDirAndCopy(srcStat, src, dest, opts, cb)
- if (destStat && !destStat.isDirectory()) {
- return cb(new Error(`Cannot overwrite non-directory '${dest}' with directory '${src}'.`))
- }
- return copyDir(src, dest, opts, cb)
-}
-
-function mkDirAndCopy (srcStat, src, dest, opts, cb) {
- fs.mkdir(dest, err => {
- if (err) return cb(err)
- copyDir(src, dest, opts, err => {
- if (err) return cb(err)
- return fs.chmod(dest, srcStat.mode, cb)
- })
- })
-}
-
-function copyDir (src, dest, opts, cb) {
- fs.readdir(src, (err, items) => {
- if (err) return cb(err)
- return copyDirItems(items, src, dest, opts, cb)
- })
-}
-
-function copyDirItems (items, src, dest, opts, cb) {
- const item = items.pop()
- if (!item) return cb()
- return copyDirItem(items, item, src, dest, opts, cb)
-}
-
-function copyDirItem (items, item, src, dest, opts, cb) {
- const srcItem = path.join(src, item)
- const destItem = path.join(dest, item)
- stat.checkPaths(srcItem, destItem, 'copy', (err, stats) => {
- if (err) return cb(err)
- const { destStat } = stats
- startCopy(destStat, srcItem, destItem, opts, err => {
- if (err) return cb(err)
- return copyDirItems(items, src, dest, opts, cb)
- })
- })
-}
-
-function onLink (destStat, src, dest, opts, cb) {
- fs.readlink(src, (err, resolvedSrc) => {
- if (err) return cb(err)
- if (opts.dereference) {
- resolvedSrc = path.resolve(process.cwd(), resolvedSrc)
- }
-
- if (!destStat) {
- return fs.symlink(resolvedSrc, dest, cb)
- } else {
- fs.readlink(dest, (err, resolvedDest) => {
- if (err) {
- // dest exists and is a regular file or directory,
- // Windows may throw UNKNOWN error. If dest already exists,
- // fs throws error anyway, so no need to guard against it here.
- if (err.code === 'EINVAL' || err.code === 'UNKNOWN') return fs.symlink(resolvedSrc, dest, cb)
- return cb(err)
- }
- if (opts.dereference) {
- resolvedDest = path.resolve(process.cwd(), resolvedDest)
- }
- if (stat.isSrcSubdir(resolvedSrc, resolvedDest)) {
- return cb(new Error(`Cannot copy '${resolvedSrc}' to a subdirectory of itself, '${resolvedDest}'.`))
- }
-
- // do not copy if src is a subdir of dest since unlinking
- // dest in this case would result in removing src contents
- // and therefore a broken symlink would be created.
- if (destStat.isDirectory() && stat.isSrcSubdir(resolvedDest, resolvedSrc)) {
- return cb(new Error(`Cannot overwrite '${resolvedDest}' with '${resolvedSrc}'.`))
- }
- return copyLink(resolvedSrc, dest, cb)
- })
- }
- })
-}
-
-function copyLink (resolvedSrc, dest, cb) {
- fs.unlink(dest, err => {
- if (err) return cb(err)
- return fs.symlink(resolvedSrc, dest, cb)
- })
-}
-
-module.exports = copy
diff --git a/node_modules/fs-extra/lib/copy/index.js b/node_modules/fs-extra/lib/copy/index.js
deleted file mode 100644
index b7e4f7f..0000000
--- a/node_modules/fs-extra/lib/copy/index.js
+++ /dev/null
@@ -1,6 +0,0 @@
-'use strict'
-
-const u = require('universalify').fromCallback
-module.exports = {
- copy: u(require('./copy'))
-}