summaryrefslogtreecommitdiff
path: root/node_modules/fs-extra/lib/copy/copy.js
diff options
context:
space:
mode:
authorLinuxWizard42 <computerwizard@linuxmail.org>2022-10-12 22:54:37 +0300
committerLinuxWizard42 <computerwizard@linuxmail.org>2022-10-12 22:54:37 +0300
commit703e03aba33f234712206769f57717ba7d92d23d (patch)
tree0041f04ccb75bd5379c764e9fe42249fffe75fc3 /node_modules/fs-extra/lib/copy/copy.js
parentab6e257e6e9d9a483d7e86f220d8b209a2cd7753 (diff)
downloadFlashRunner-703e03aba33f234712206769f57717ba7d92d23d.tar.gz
FlashRunner-703e03aba33f234712206769f57717ba7d92d23d.tar.zst
Added export_allowed file to make repository visible in cgit
Diffstat (limited to 'node_modules/fs-extra/lib/copy/copy.js')
-rw-r--r--node_modules/fs-extra/lib/copy/copy.js54
1 files changed, 54 insertions, 0 deletions
diff --git a/node_modules/fs-extra/lib/copy/copy.js b/node_modules/fs-extra/lib/copy/copy.js
new file mode 100644
index 0000000..309a93d
--- /dev/null
+++ b/node_modules/fs-extra/lib/copy/copy.js
@@ -0,0 +1,54 @@
+'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) {
+ callback = options
+ options = {}
+ } else if (typeof options === 'function' || options instanceof RegExp) {
+ options = {filter: options}
+ }
+ 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
+ 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, (err, stats) => {
+ if (err) return callback(err)
+
+ let dir = null
+ if (stats.isDirectory()) {
+ const parts = dest.split(path.sep)
+ parts.pop()
+ dir = parts.join(path.sep)
+ } else {
+ dir = path.dirname(dest)
+ }
+
+ pathExists(dir, (err, dirExists) => {
+ if (err) return callback(err)
+ if (dirExists) return ncp(src, dest, options, callback)
+ mkdir.mkdirs(dir, err => {
+ if (err) return callback(err)
+ ncp(src, dest, options, callback)
+ })
+ })
+ })
+}
+
+module.exports = copy