summaryrefslogtreecommitdiff
path: root/node_modules/fs-extra/lib/copy
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2026-05-18 23:10:59 +0800
committerlittleblack111 <littleblack11111@gmail.com>2026-05-18 23:41:44 +0800
commitfc87c009806dcc98867f6b58efe29b042aa01dee (patch)
tree8f59b3f4a5b66e9dfef2d40c8d318e258a521228 /node_modules/fs-extra/lib/copy
parent3336b2356ee6152d9c6ae59bd9b87ccbc0958407 (diff)
node: updatemain
Diffstat (limited to 'node_modules/fs-extra/lib/copy')
-rw-r--r--node_modules/fs-extra/lib/copy/copy-sync.js161
-rw-r--r--node_modules/fs-extra/lib/copy/copy.js177
-rw-r--r--node_modules/fs-extra/lib/copy/index.js7
3 files changed, 0 insertions, 345 deletions
diff --git a/node_modules/fs-extra/lib/copy/copy-sync.js b/node_modules/fs-extra/lib/copy/copy-sync.js
deleted file mode 100644
index 8bc60119..00000000
--- a/node_modules/fs-extra/lib/copy/copy-sync.js
+++ /dev/null
@@ -1,161 +0,0 @@
-'use strict'
-
-const fs = require('graceful-fs')
-const path = require('path')
-const mkdirsSync = require('../mkdirs').mkdirsSync
-const utimesMillisSync = require('../util/utimes').utimesMillisSync
-const stat = require('../util/stat')
-
-function copySync (src, dest, opts) {
- if (typeof opts === 'function') {
- opts = { filter: opts }
- }
-
- 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') {
- process.emitWarning(
- 'Using the preserveTimestamps option in 32-bit node is not recommended;\n\n' +
- '\tsee https://github.com/jprichardson/node-fs-extra/issues/269',
- 'Warning', 'fs-extra-WARN0002'
- )
- }
-
- const { srcStat, destStat } = stat.checkPathsSync(src, dest, 'copy', opts)
- stat.checkParentPathsSync(src, srcStat, dest, 'copy')
- if (opts.filter && !opts.filter(src, dest)) return
- const destParent = path.dirname(dest)
- if (!fs.existsSync(destParent)) mkdirsSync(destParent)
- return getStats(destStat, src, dest, opts)
-}
-
-function getStats (destStat, src, dest, opts) {
- const statSync = opts.dereference ? fs.statSync : fs.lstatSync
- const srcStat = statSync(src)
-
- if (srcStat.isDirectory()) return onDir(srcStat, destStat, src, dest, opts)
- else if (srcStat.isFile() ||
- srcStat.isCharacterDevice() ||
- srcStat.isBlockDevice()) return onFile(srcStat, destStat, src, dest, opts)
- else if (srcStat.isSymbolicLink()) return onLink(destStat, src, dest, opts)
- else if (srcStat.isSocket()) throw new Error(`Cannot copy a socket file: ${src}`)
- else if (srcStat.isFIFO()) throw new Error(`Cannot copy a FIFO pipe: ${src}`)
- throw new Error(`Unknown file: ${src}`)
-}
-
-function onFile (srcStat, destStat, src, dest, opts) {
- if (!destStat) return copyFile(srcStat, src, dest, opts)
- return mayCopyFile(srcStat, src, dest, opts)
-}
-
-function mayCopyFile (srcStat, src, dest, opts) {
- if (opts.overwrite) {
- fs.unlinkSync(dest)
- return copyFile(srcStat, src, dest, opts)
- } else if (opts.errorOnExist) {
- throw new Error(`'${dest}' already exists`)
- }
-}
-
-function copyFile (srcStat, src, dest, opts) {
- fs.copyFileSync(src, dest)
- if (opts.preserveTimestamps) handleTimestamps(srcStat.mode, src, dest)
- return setDestMode(dest, srcStat.mode)
-}
-
-function handleTimestamps (srcMode, src, dest) {
- // Make sure the file is writable before setting the timestamp
- // otherwise open fails with EPERM when invoked with 'r+'
- // (through utimes call)
- if (fileIsNotWritable(srcMode)) makeFileWritable(dest, srcMode)
- return setDestTimestamps(src, dest)
-}
-
-function fileIsNotWritable (srcMode) {
- return (srcMode & 0o200) === 0
-}
-
-function makeFileWritable (dest, srcMode) {
- return setDestMode(dest, srcMode | 0o200)
-}
-
-function setDestMode (dest, srcMode) {
- return fs.chmodSync(dest, srcMode)
-}
-
-function setDestTimestamps (src, dest) {
- // The initial srcStat.atime cannot be trusted
- // because it is modified by the read(2) system call
- // (See https://nodejs.org/api/fs.html#fs_stat_time_values)
- const updatedSrcStat = fs.statSync(src)
- return utimesMillisSync(dest, updatedSrcStat.atime, updatedSrcStat.mtime)
-}
-
-function onDir (srcStat, destStat, src, dest, opts) {
- if (!destStat) return mkDirAndCopy(srcStat.mode, src, dest, opts)
- return copyDir(src, dest, opts)
-}
-
-function mkDirAndCopy (srcMode, src, dest, opts) {
- fs.mkdirSync(dest)
- copyDir(src, dest, opts)
- return setDestMode(dest, srcMode)
-}
-
-function copyDir (src, dest, opts) {
- fs.readdirSync(src).forEach(item => copyDirItem(item, src, dest, opts))
-}
-
-function copyDirItem (item, src, dest, opts) {
- const srcItem = path.join(src, item)
- const destItem = path.join(dest, item)
- if (opts.filter && !opts.filter(srcItem, destItem)) return
- const { destStat } = stat.checkPathsSync(srcItem, destItem, 'copy', opts)
- return getStats(destStat, srcItem, destItem, opts)
-}
-
-function onLink (destStat, src, dest, opts) {
- let resolvedSrc = fs.readlinkSync(src)
- if (opts.dereference) {
- resolvedSrc = path.resolve(process.cwd(), resolvedSrc)
- }
-
- if (!destStat) {
- return fs.symlinkSync(resolvedSrc, dest)
- } else {
- let resolvedDest
- try {
- resolvedDest = fs.readlinkSync(dest)
- } catch (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.symlinkSync(resolvedSrc, dest)
- throw err
- }
- if (opts.dereference) {
- resolvedDest = path.resolve(process.cwd(), resolvedDest)
- }
- if (stat.isSrcSubdir(resolvedSrc, resolvedDest)) {
- throw new Error(`Cannot copy '${resolvedSrc}' to a subdirectory of itself, '${resolvedDest}'.`)
- }
-
- // prevent 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 (stat.isSrcSubdir(resolvedDest, resolvedSrc)) {
- throw new Error(`Cannot overwrite '${resolvedDest}' with '${resolvedSrc}'.`)
- }
- return copyLink(resolvedSrc, dest)
- }
-}
-
-function copyLink (resolvedSrc, dest) {
- fs.unlinkSync(dest)
- return fs.symlinkSync(resolvedSrc, dest)
-}
-
-module.exports = copySync
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 6304b021..00000000
--- a/node_modules/fs-extra/lib/copy/copy.js
+++ /dev/null
@@ -1,177 +0,0 @@
-'use strict'
-
-const fs = require('../fs')
-const path = require('path')
-const { mkdirs } = require('../mkdirs')
-const { pathExists } = require('../path-exists')
-const { utimesMillis } = require('../util/utimes')
-const stat = require('../util/stat')
-
-async function copy (src, dest, opts = {}) {
- if (typeof opts === 'function') {
- opts = { filter: 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') {
- process.emitWarning(
- 'Using the preserveTimestamps option in 32-bit node is not recommended;\n\n' +
- '\tsee https://github.com/jprichardson/node-fs-extra/issues/269',
- 'Warning', 'fs-extra-WARN0001'
- )
- }
-
- const { srcStat, destStat } = await stat.checkPaths(src, dest, 'copy', opts)
-
- await stat.checkParentPaths(src, srcStat, dest, 'copy')
-
- const include = await runFilter(src, dest, opts)
-
- if (!include) return
-
- // check if the parent of dest exists, and create it if it doesn't exist
- const destParent = path.dirname(dest)
- const dirExists = await pathExists(destParent)
- if (!dirExists) {
- await mkdirs(destParent)
- }
-
- await getStatsAndPerformCopy(destStat, src, dest, opts)
-}
-
-async function runFilter (src, dest, opts) {
- if (!opts.filter) return true
- return opts.filter(src, dest)
-}
-
-async function getStatsAndPerformCopy (destStat, src, dest, opts) {
- const statFn = opts.dereference ? fs.stat : fs.lstat
- const srcStat = await statFn(src)
-
- if (srcStat.isDirectory()) return onDir(srcStat, destStat, src, dest, opts)
-
- if (
- srcStat.isFile() ||
- srcStat.isCharacterDevice() ||
- srcStat.isBlockDevice()
- ) return onFile(srcStat, destStat, src, dest, opts)
-
- if (srcStat.isSymbolicLink()) return onLink(destStat, src, dest, opts)
- if (srcStat.isSocket()) throw new Error(`Cannot copy a socket file: ${src}`)
- if (srcStat.isFIFO()) throw new Error(`Cannot copy a FIFO pipe: ${src}`)
- throw new Error(`Unknown file: ${src}`)
-}
-
-async function onFile (srcStat, destStat, src, dest, opts) {
- if (!destStat) return copyFile(srcStat, src, dest, opts)
-
- if (opts.overwrite) {
- await fs.unlink(dest)
- return copyFile(srcStat, src, dest, opts)
- }
- if (opts.errorOnExist) {
- throw new Error(`'${dest}' already exists`)
- }
-}
-
-async function copyFile (srcStat, src, dest, opts) {
- await fs.copyFile(src, dest)
- if (opts.preserveTimestamps) {
- // Make sure the file is writable before setting the timestamp
- // otherwise open fails with EPERM when invoked with 'r+'
- // (through utimes call)
- if (fileIsNotWritable(srcStat.mode)) {
- await makeFileWritable(dest, srcStat.mode)
- }
-
- // Set timestamps and mode correspondingly
-
- // Note that The initial srcStat.atime cannot be trusted
- // because it is modified by the read(2) system call
- // (See https://nodejs.org/api/fs.html#fs_stat_time_values)
- const updatedSrcStat = await fs.stat(src)
- await utimesMillis(dest, updatedSrcStat.atime, updatedSrcStat.mtime)
- }
-
- return fs.chmod(dest, srcStat.mode)
-}
-
-function fileIsNotWritable (srcMode) {
- return (srcMode & 0o200) === 0
-}
-
-function makeFileWritable (dest, srcMode) {
- return fs.chmod(dest, srcMode | 0o200)
-}
-
-async function onDir (srcStat, destStat, src, dest, opts) {
- // the dest directory might not exist, create it
- if (!destStat) {
- await fs.mkdir(dest)
- }
-
- const items = await fs.readdir(src)
-
- // loop through the files in the current directory to copy everything
- await Promise.all(items.map(async item => {
- const srcItem = path.join(src, item)
- const destItem = path.join(dest, item)
-
- // skip the item if it is matches by the filter function
- const include = await runFilter(srcItem, destItem, opts)
- if (!include) return
-
- const { destStat } = await stat.checkPaths(srcItem, destItem, 'copy', opts)
-
- // If the item is a copyable file, `getStatsAndPerformCopy` will copy it
- // If the item is a directory, `getStatsAndPerformCopy` will call `onDir` recursively
- return getStatsAndPerformCopy(destStat, srcItem, destItem, opts)
- }))
-
- if (!destStat) {
- await fs.chmod(dest, srcStat.mode)
- }
-}
-
-async function onLink (destStat, src, dest, opts) {
- let resolvedSrc = await fs.readlink(src)
- if (opts.dereference) {
- resolvedSrc = path.resolve(process.cwd(), resolvedSrc)
- }
- if (!destStat) {
- return fs.symlink(resolvedSrc, dest)
- }
-
- let resolvedDest = null
- try {
- resolvedDest = await fs.readlink(dest)
- } catch (e) {
- // 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 (e.code === 'EINVAL' || e.code === 'UNKNOWN') return fs.symlink(resolvedSrc, dest)
- throw e
- }
- if (opts.dereference) {
- resolvedDest = path.resolve(process.cwd(), resolvedDest)
- }
- if (stat.isSrcSubdir(resolvedSrc, resolvedDest)) {
- throw 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 (stat.isSrcSubdir(resolvedDest, resolvedSrc)) {
- throw new Error(`Cannot overwrite '${resolvedDest}' with '${resolvedSrc}'.`)
- }
-
- // copy the link
- await fs.unlink(dest)
- return fs.symlink(resolvedSrc, dest)
-}
-
-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 2e31d278..00000000
--- a/node_modules/fs-extra/lib/copy/index.js
+++ /dev/null
@@ -1,7 +0,0 @@
-'use strict'
-
-const u = require('universalify').fromPromise
-module.exports = {
- copy: u(require('./copy')),
- copySync: require('./copy-sync')
-}