summaryrefslogtreecommitdiff
path: root/node_modules/fs-extra/lib/util
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2023-12-21 22:46:53 +0800
committerlittleblack111 <littleblack11111@gmail.com>2023-12-21 22:46:53 +0800
commitf06956efd2dc4bf77244a9fcce2b883a00b925af (patch)
tree0123cb73ce67f1f4b17e1d6cbabff076ee44e31b /node_modules/fs-extra/lib/util
parent8d980c13970c15b6d2312b6fc4ac51698dd0d220 (diff)
updated node modules
Diffstat (limited to 'node_modules/fs-extra/lib/util')
-rw-r--r--node_modules/fs-extra/lib/util/stat.js88
-rw-r--r--node_modules/fs-extra/lib/util/utimes.js32
2 files changed, 67 insertions, 53 deletions
diff --git a/node_modules/fs-extra/lib/util/stat.js b/node_modules/fs-extra/lib/util/stat.js
index 0ed5aecf..dfd37d9c 100644
--- a/node_modules/fs-extra/lib/util/stat.js
+++ b/node_modules/fs-extra/lib/util/stat.js
@@ -2,7 +2,7 @@
const fs = require('../fs')
const path = require('path')
-const util = require('util')
+const u = require('universalify').fromPromise
function getStats (src, dest, opts) {
const statFunc = opts.dereference
@@ -32,35 +32,32 @@ function getStatsSync (src, dest, opts) {
return { srcStat, destStat }
}
-function checkPaths (src, dest, funcName, opts, cb) {
- util.callbackify(getStats)(src, dest, opts, (err, stats) => {
- if (err) return cb(err)
- const { srcStat, destStat } = stats
-
- if (destStat) {
- if (areIdentical(srcStat, destStat)) {
- const srcBaseName = path.basename(src)
- const destBaseName = path.basename(dest)
- if (funcName === 'move' &&
- srcBaseName !== destBaseName &&
- srcBaseName.toLowerCase() === destBaseName.toLowerCase()) {
- return cb(null, { srcStat, destStat, isChangingCase: true })
- }
- return cb(new Error('Source and destination must not be the same.'))
- }
- if (srcStat.isDirectory() && !destStat.isDirectory()) {
- return cb(new Error(`Cannot overwrite non-directory '${dest}' with directory '${src}'.`))
- }
- if (!srcStat.isDirectory() && destStat.isDirectory()) {
- return cb(new Error(`Cannot overwrite directory '${dest}' with non-directory '${src}'.`))
+async function checkPaths (src, dest, funcName, opts) {
+ const { srcStat, destStat } = await getStats(src, dest, opts)
+ if (destStat) {
+ if (areIdentical(srcStat, destStat)) {
+ const srcBaseName = path.basename(src)
+ const destBaseName = path.basename(dest)
+ if (funcName === 'move' &&
+ srcBaseName !== destBaseName &&
+ srcBaseName.toLowerCase() === destBaseName.toLowerCase()) {
+ return { srcStat, destStat, isChangingCase: true }
}
+ throw new Error('Source and destination must not be the same.')
}
-
- if (srcStat.isDirectory() && isSrcSubdir(src, dest)) {
- return cb(new Error(errMsg(src, dest, funcName)))
+ if (srcStat.isDirectory() && !destStat.isDirectory()) {
+ throw new Error(`Cannot overwrite non-directory '${dest}' with directory '${src}'.`)
+ }
+ if (!srcStat.isDirectory() && destStat.isDirectory()) {
+ throw new Error(`Cannot overwrite directory '${dest}' with non-directory '${src}'.`)
}
- return cb(null, { srcStat, destStat })
- })
+ }
+
+ if (srcStat.isDirectory() && isSrcSubdir(src, dest)) {
+ throw new Error(errMsg(src, dest, funcName))
+ }
+
+ return { srcStat, destStat }
}
function checkPathsSync (src, dest, funcName, opts) {
@@ -95,20 +92,24 @@ function checkPathsSync (src, dest, funcName, opts) {
// It works for all file types including symlinks since it
// checks the src and dest inodes. It starts from the deepest
// parent and stops once it reaches the src parent or the root path.
-function checkParentPaths (src, srcStat, dest, funcName, cb) {
+async function checkParentPaths (src, srcStat, dest, funcName) {
const srcParent = path.resolve(path.dirname(src))
const destParent = path.resolve(path.dirname(dest))
- if (destParent === srcParent || destParent === path.parse(destParent).root) return cb()
- fs.stat(destParent, { bigint: true }, (err, destStat) => {
- if (err) {
- if (err.code === 'ENOENT') return cb()
- return cb(err)
- }
- if (areIdentical(srcStat, destStat)) {
- return cb(new Error(errMsg(src, dest, funcName)))
- }
- return checkParentPaths(src, srcStat, destParent, funcName, cb)
- })
+ if (destParent === srcParent || destParent === path.parse(destParent).root) return
+
+ let destStat
+ try {
+ destStat = await fs.stat(destParent, { bigint: true })
+ } catch (err) {
+ if (err.code === 'ENOENT') return
+ throw err
+ }
+
+ if (areIdentical(srcStat, destStat)) {
+ throw new Error(errMsg(src, dest, funcName))
+ }
+
+ return checkParentPaths(src, srcStat, destParent, funcName)
}
function checkParentPathsSync (src, srcStat, dest, funcName) {
@@ -137,7 +138,7 @@ function areIdentical (srcStat, destStat) {
function isSrcSubdir (src, dest) {
const srcArr = path.resolve(src).split(path.sep).filter(i => i)
const destArr = path.resolve(dest).split(path.sep).filter(i => i)
- return srcArr.reduce((acc, cur, i) => acc && destArr[i] === cur, true)
+ return srcArr.every((cur, i) => destArr[i] === cur)
}
function errMsg (src, dest, funcName) {
@@ -145,10 +146,13 @@ function errMsg (src, dest, funcName) {
}
module.exports = {
- checkPaths,
+ // checkPaths
+ checkPaths: u(checkPaths),
checkPathsSync,
- checkParentPaths,
+ // checkParent
+ checkParentPaths: u(checkParentPaths),
checkParentPathsSync,
+ // Misc
isSrcSubdir,
areIdentical
}
diff --git a/node_modules/fs-extra/lib/util/utimes.js b/node_modules/fs-extra/lib/util/utimes.js
index 75395def..87f4588c 100644
--- a/node_modules/fs-extra/lib/util/utimes.js
+++ b/node_modules/fs-extra/lib/util/utimes.js
@@ -1,17 +1,27 @@
'use strict'
-const fs = require('graceful-fs')
+const fs = require('../fs')
+const u = require('universalify').fromPromise
-function utimesMillis (path, atime, mtime, callback) {
+async function utimesMillis (path, atime, mtime) {
// if (!HAS_MILLIS_RES) return fs.utimes(path, atime, mtime, callback)
- fs.open(path, 'r+', (err, fd) => {
- if (err) return callback(err)
- fs.futimes(fd, atime, mtime, futimesErr => {
- fs.close(fd, closeErr => {
- if (callback) callback(futimesErr || closeErr)
- })
- })
- })
+ const fd = await fs.open(path, 'r+')
+
+ let closeErr = null
+
+ try {
+ await fs.futimes(fd, atime, mtime)
+ } finally {
+ try {
+ await fs.close(fd)
+ } catch (e) {
+ closeErr = e
+ }
+ }
+
+ if (closeErr) {
+ throw closeErr
+ }
}
function utimesMillisSync (path, atime, mtime) {
@@ -21,6 +31,6 @@ function utimesMillisSync (path, atime, mtime) {
}
module.exports = {
- utimesMillis,
+ utimesMillis: u(utimesMillis),
utimesMillisSync
}