aboutsummaryrefslogtreecommitdiff
path: root/node_modules/fs-extra/lib/move-sync
diff options
context:
space:
mode:
authorPriyansh <[email protected]>2020-12-22 17:49:59 +0530
committerPriyansh <[email protected]>2020-12-22 17:49:59 +0530
commite93da8b04da86773247aadb1cbb1912e4f4526b2 (patch)
treeeb4ef3203a92ed3dbd2252ddb1ea23bd2d670c98 /node_modules/fs-extra/lib/move-sync
parenta5743c293dcb435e4b159a4df791f8955a4110ec (diff)
downloadstyx-e93da8b04da86773247aadb1cbb1912e4f4526b2.tar.xz
styx-e93da8b04da86773247aadb1cbb1912e4f4526b2.zip
Rewriting Project
Diffstat (limited to 'node_modules/fs-extra/lib/move-sync')
-rw-r--r--node_modules/fs-extra/lib/move-sync/index.js5
-rw-r--r--node_modules/fs-extra/lib/move-sync/move-sync.js47
2 files changed, 52 insertions, 0 deletions
diff --git a/node_modules/fs-extra/lib/move-sync/index.js b/node_modules/fs-extra/lib/move-sync/index.js
new file mode 100644
index 0000000..af90b06
--- /dev/null
+++ b/node_modules/fs-extra/lib/move-sync/index.js
@@ -0,0 +1,5 @@
+'use strict'
+
+module.exports = {
+ moveSync: require('./move-sync')
+}
diff --git a/node_modules/fs-extra/lib/move-sync/move-sync.js b/node_modules/fs-extra/lib/move-sync/move-sync.js
new file mode 100644
index 0000000..20f910c
--- /dev/null
+++ b/node_modules/fs-extra/lib/move-sync/move-sync.js
@@ -0,0 +1,47 @@
+'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').mkdirpSync
+const stat = require('../util/stat')
+
+function moveSync (src, dest, opts) {
+ opts = opts || {}
+ const overwrite = opts.overwrite || opts.clobber || false
+
+ const { srcStat } = stat.checkPathsSync(src, dest, 'move')
+ stat.checkParentPathsSync(src, srcStat, dest, 'move')
+ mkdirpSync(path.dirname(dest))
+ return doRename(src, dest, overwrite)
+}
+
+function doRename (src, dest, overwrite) {
+ if (overwrite) {
+ removeSync(dest)
+ return rename(src, dest, overwrite)
+ }
+ if (fs.existsSync(dest)) throw new Error('dest already exists.')
+ return rename(src, dest, overwrite)
+}
+
+function rename (src, dest, overwrite) {
+ try {
+ fs.renameSync(src, dest)
+ } catch (err) {
+ if (err.code !== 'EXDEV') throw err
+ return moveAcrossDevice(src, dest, overwrite)
+ }
+}
+
+function moveAcrossDevice (src, dest, overwrite) {
+ const opts = {
+ overwrite,
+ errorOnExist: true
+ }
+ copySync(src, dest, opts)
+ return removeSync(src)
+}
+
+module.exports = moveSync