From 1424fdc8bbc4764253e65cebee73b98289268217 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 13 May 2021 00:15:32 +0200 Subject: [PATCH] Bump fs-extra from 9.1.0 to 10.0.0 (#139) * Bump fs-extra from 9.1.0 to 10.0.0 Bumps [fs-extra](https://github.com/jprichardson/node-fs-extra) from 9.1.0 to 10.0.0. - [Release notes](https://github.com/jprichardson/node-fs-extra/releases) - [Changelog](https://github.com/jprichardson/node-fs-extra/blob/master/CHANGELOG.md) - [Commits](https://github.com/jprichardson/node-fs-extra/compare/9.1.0...10.0.0) Signed-off-by: dependabot[bot] * Update generated content Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: CrazyMax --- dist/index.js | 469 ++++++++++++++++++++++---------------------------- package.json | 2 +- yarn.lock | 14 +- 3 files changed, 209 insertions(+), 276 deletions(-) diff --git a/dist/index.js b/dist/index.js index 2c73c8566eb..6c2ae7c8200 100644 --- a/dist/index.js +++ b/dist/index.js @@ -2207,18 +2207,6 @@ Tokenizer.prototype.checkChar = function (chr) { }; -/***/ }), - -/***/ 5995: -/***/ ((module) => { - -module.exports = r => { - const n = process.versions.node.split('.').map(x => parseInt(x, 10)) - r = r.split('.').map(x => parseInt(x, 10)) - return n[0] > r[0] || (n[0] === r[0] && (n[1] > r[1] || (n[1] === r[1] && n[2] >= r[2]))) -} - - /***/ }), /***/ 3338: @@ -2248,7 +2236,7 @@ function copySync (src, dest, opts) { see https://github.com/jprichardson/node-fs-extra/issues/269`) } - const { srcStat, destStat } = stat.checkPathsSync(src, dest, 'copy') + const { srcStat, destStat } = stat.checkPathsSync(src, dest, 'copy', opts) stat.checkParentPathsSync(src, srcStat, dest, 'copy') return handleFilterAndCopy(destStat, src, dest, opts) } @@ -2257,7 +2245,7 @@ function handleFilterAndCopy (destStat, src, dest, opts) { if (opts.filter && !opts.filter(src, dest)) return const destParent = path.dirname(dest) if (!fs.existsSync(destParent)) mkdirsSync(destParent) - return startCopy(destStat, src, dest, opts) + return getStats(destStat, src, dest, opts) } function startCopy (destStat, src, dest, opts) { @@ -2274,6 +2262,9 @@ function getStats (destStat, src, dest, opts) { 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) { @@ -2326,9 +2317,6 @@ function setDestTimestamps (src, dest) { function onDir (srcStat, destStat, src, dest, opts) { if (!destStat) return mkDirAndCopy(srcStat.mode, src, dest, opts) - if (destStat && !destStat.isDirectory()) { - throw new Error(`Cannot overwrite non-directory '${dest}' with directory '${src}'.`) - } return copyDir(src, dest, opts) } @@ -2345,7 +2333,7 @@ function copyDir (src, dest, opts) { function copyDirItem (item, src, dest, opts) { const srcItem = path.join(src, item) const destItem = path.join(dest, item) - const { destStat } = stat.checkPathsSync(srcItem, destItem, 'copy') + const { destStat } = stat.checkPathsSync(srcItem, destItem, 'copy', opts) return startCopy(destStat, srcItem, destItem, opts) } @@ -2441,7 +2429,7 @@ function copy (src, dest, opts, cb) { see https://github.com/jprichardson/node-fs-extra/issues/269`) } - stat.checkPaths(src, dest, 'copy', (err, stats) => { + stat.checkPaths(src, dest, 'copy', opts, (err, stats) => { if (err) return cb(err) const { srcStat, destStat } = stats stat.checkParentPaths(src, srcStat, dest, 'copy', err => { @@ -2456,10 +2444,10 @@ 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) + if (dirExists) return getStats(destStat, src, dest, opts, cb) mkdirs(destParent, err => { if (err) return cb(err) - return startCopy(destStat, src, dest, opts, cb) + return getStats(destStat, src, dest, opts, cb) }) }) } @@ -2486,6 +2474,9 @@ function getStats (destStat, src, dest, opts, cb) { srcStat.isCharacterDevice() || srcStat.isBlockDevice()) return onFile(srcStat, destStat, src, dest, opts, cb) else if (srcStat.isSymbolicLink()) return onLink(destStat, src, dest, opts, cb) + else if (srcStat.isSocket()) return cb(new Error(`Cannot copy a socket file: ${src}`)) + else if (srcStat.isFIFO()) return cb(new Error(`Cannot copy a FIFO pipe: ${src}`)) + return cb(new Error(`Unknown file: ${src}`)) }) } @@ -2557,9 +2548,6 @@ function setDestTimestamps (src, dest, cb) { function onDir (srcStat, destStat, src, dest, opts, cb) { if (!destStat) return mkDirAndCopy(srcStat.mode, 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) } @@ -2589,7 +2577,7 @@ function copyDirItems (items, 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) => { + stat.checkPaths(srcItem, destItem, 'copy', opts, (err, stats) => { if (err) return cb(err) const { destStat } = stats startCopy(destStat, srcItem, destItem, opts, err => { @@ -2668,30 +2656,21 @@ module.exports = { "use strict"; -const u = __webpack_require__(9046).fromCallback -const fs = __webpack_require__(7758) +const u = __webpack_require__(9046).fromPromise +const fs = __webpack_require__(1176) const path = __webpack_require__(5622) const mkdir = __webpack_require__(8605) const remove = __webpack_require__(7357) -const emptyDir = u(function emptyDir (dir, callback) { - callback = callback || function () {} - fs.readdir(dir, (err, items) => { - if (err) return mkdir.mkdirs(dir, callback) - - items = items.map(item => path.join(dir, item)) - - deleteItem() +const emptyDir = u(async function emptyDir (dir) { + let items + try { + items = await fs.readdir(dir) + } catch { + return mkdir.mkdirs(dir) + } - function deleteItem () { - const item = items.pop() - if (!item) return callback() - remove.remove(item, err => { - if (err) return callback(err) - deleteItem() - }) - } - }) + return Promise.all(items.map(item => remove.remove(path.join(dir, item)))) }) function emptyDirSync (dir) { @@ -2837,6 +2816,7 @@ const path = __webpack_require__(5622) const fs = __webpack_require__(7758) const mkdir = __webpack_require__(8605) const pathExists = __webpack_require__(3835).pathExists +const { areIdentical } = __webpack_require__(3901) function createLink (srcpath, dstpath, callback) { function makeLink (srcpath, dstpath) { @@ -2846,14 +2826,13 @@ function createLink (srcpath, dstpath, callback) { }) } - pathExists(dstpath, (err, destinationExists) => { - if (err) return callback(err) - if (destinationExists) return callback(null) - fs.lstat(srcpath, (err) => { + fs.lstat(dstpath, (_, dstStat) => { + fs.lstat(srcpath, (err, srcStat) => { if (err) { err.message = err.message.replace('lstat', 'ensureLink') return callback(err) } + if (dstStat && areIdentical(srcStat, dstStat)) return callback(null) const dir = path.dirname(dstpath) pathExists(dir, (err, dirExists) => { @@ -2869,11 +2848,14 @@ function createLink (srcpath, dstpath, callback) { } function createLinkSync (srcpath, dstpath) { - const destinationExists = fs.existsSync(dstpath) - if (destinationExists) return undefined + let dstStat + try { + dstStat = fs.lstatSync(dstpath) + } catch {} try { - fs.lstatSync(srcpath) + const srcStat = fs.lstatSync(srcpath) + if (dstStat && areIdentical(srcStat, dstStat)) return } catch (err) { err.message = err.message.replace('lstat', 'ensureLink') throw err @@ -3049,7 +3031,7 @@ module.exports = { const u = __webpack_require__(9046).fromCallback const path = __webpack_require__(5622) -const fs = __webpack_require__(7758) +const fs = __webpack_require__(1176) const _mkdirs = __webpack_require__(8605) const mkdirs = _mkdirs.mkdirs const mkdirsSync = _mkdirs.mkdirsSync @@ -3064,26 +3046,38 @@ const symlinkTypeSync = _symlinkType.symlinkTypeSync const pathExists = __webpack_require__(3835).pathExists +const { areIdentical } = __webpack_require__(3901) + function createSymlink (srcpath, dstpath, type, callback) { callback = (typeof type === 'function') ? type : callback type = (typeof type === 'function') ? false : type - pathExists(dstpath, (err, destinationExists) => { + fs.lstat(dstpath, (err, stats) => { + if (!err && stats.isSymbolicLink()) { + Promise.all([ + fs.stat(srcpath), + fs.stat(dstpath) + ]).then(([srcStat, dstStat]) => { + if (areIdentical(srcStat, dstStat)) return callback(null) + _createSymlink(srcpath, dstpath, type, callback) + }) + } else _createSymlink(srcpath, dstpath, type, callback) + }) +} + +function _createSymlink (srcpath, dstpath, type, callback) { + symlinkPaths(srcpath, dstpath, (err, relative) => { if (err) return callback(err) - if (destinationExists) return callback(null) - symlinkPaths(srcpath, dstpath, (err, relative) => { + srcpath = relative.toDst + symlinkType(relative.toCwd, type, (err, type) => { if (err) return callback(err) - srcpath = relative.toDst - symlinkType(relative.toCwd, type, (err, type) => { + const dir = path.dirname(dstpath) + pathExists(dir, (err, dirExists) => { if (err) return callback(err) - const dir = path.dirname(dstpath) - pathExists(dir, (err, dirExists) => { + if (dirExists) return fs.symlink(srcpath, dstpath, type, callback) + mkdirs(dir, err => { if (err) return callback(err) - if (dirExists) return fs.symlink(srcpath, dstpath, type, callback) - mkdirs(dir, err => { - if (err) return callback(err) - fs.symlink(srcpath, dstpath, type, callback) - }) + fs.symlink(srcpath, dstpath, type, callback) }) }) }) @@ -3091,8 +3085,15 @@ function createSymlink (srcpath, dstpath, type, callback) { } function createSymlinkSync (srcpath, dstpath, type) { - const destinationExists = fs.existsSync(dstpath) - if (destinationExists) return undefined + let stats + try { + stats = fs.lstatSync(dstpath) + } catch {} + if (stats && stats.isSymbolicLink()) { + const srcStat = fs.statSync(srcpath) + const dstStat = fs.statSync(dstpath) + if (areIdentical(srcStat, dstStat)) return + } const relative = symlinkPathsSync(srcpath, dstpath) srcpath = relative.toDst @@ -3165,20 +3166,14 @@ const api = [ return typeof fs[key] === 'function' }) -// Export all keys: -Object.keys(fs).forEach(key => { - if (key === 'promises') { - // fs.promises is a getter property that triggers ExperimentalWarning - // Don't re-export it here, the getter is defined in "lib/index.js" - return - } - exports[key] = fs[key] -}) +// Export cloned fs: +Object.assign(exports, fs) // Universalify async methods: api.forEach(method => { exports[method] = u(fs[method]) }) +exports.realpath.native = u(fs.realpath.native) // We differ from mz/fs in that we still ship the old, broken, fs.exists() // since we are a drop-in replacement for the native module @@ -3242,11 +3237,6 @@ if (typeof fs.writev === 'function') { } } -// fs.realpath.native only available in Node v9.2+ -if (typeof fs.realpath.native === 'function') { - exports.realpath.native = u(fs.realpath.native) -} - /***/ }), @@ -3273,15 +3263,6 @@ module.exports = { ...__webpack_require__(7357) } -// Export fs.promises as a getter property so that we don't trigger -// ExperimentalWarning before fs.promises is actually accessed. -const fs = __webpack_require__(5747) -if (Object.getOwnPropertyDescriptor(fs, 'promises')) { - Object.defineProperty(module.exports, "promises", ({ - get () { return fs.promises } - })) -} - /***/ }), @@ -3394,146 +3375,61 @@ module.exports = { /***/ ((module, __unused_webpack_exports, __webpack_require__) => { "use strict"; -// Adapted from https://github.com/sindresorhus/make-dir -// Copyright (c) Sindre Sorhus (sindresorhus.com) -// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. const fs = __webpack_require__(1176) -const path = __webpack_require__(5622) -const atLeastNode = __webpack_require__(5995) - -const useNativeRecursiveOption = atLeastNode('10.12.0') +const { checkPath } = __webpack_require__(9907) -// https://github.com/nodejs/node/issues/8987 -// https://github.com/libuv/libuv/pull/1088 -const checkPath = pth => { - if (process.platform === 'win32') { - const pathHasInvalidWinCharacters = /[<>:"|?*]/.test(pth.replace(path.parse(pth).root, '')) - - if (pathHasInvalidWinCharacters) { - const error = new Error(`Path contains invalid characters: ${pth}`) - error.code = 'EINVAL' - throw error - } - } -} - -const processOptions = options => { +const getMode = options => { const defaults = { mode: 0o777 } - if (typeof options === 'number') options = { mode: options } - return { ...defaults, ...options } + if (typeof options === 'number') return options + return ({ ...defaults, ...options }).mode } -const permissionError = pth => { - // This replicates the exception of `fs.mkdir` with native the - // `recusive` option when run on an invalid drive under Windows. - const error = new Error(`operation not permitted, mkdir '${pth}'`) - error.code = 'EPERM' - error.errno = -4048 - error.path = pth - error.syscall = 'mkdir' - return error -} - -module.exports.makeDir = async (input, options) => { - checkPath(input) - options = processOptions(options) - - if (useNativeRecursiveOption) { - const pth = path.resolve(input) - - return fs.mkdir(pth, { - mode: options.mode, - recursive: true - }) - } - - const make = async pth => { - try { - await fs.mkdir(pth, options.mode) - } catch (error) { - if (error.code === 'EPERM') { - throw error - } +module.exports.makeDir = async (dir, options) => { + checkPath(dir) - if (error.code === 'ENOENT') { - if (path.dirname(pth) === pth) { - throw permissionError(pth) - } - - if (error.message.includes('null bytes')) { - throw error - } + return fs.mkdir(dir, { + mode: getMode(options), + recursive: true + }) +} - await make(path.dirname(pth)) - return make(pth) - } +module.exports.makeDirSync = (dir, options) => { + checkPath(dir) - try { - const stats = await fs.stat(pth) - if (!stats.isDirectory()) { - // This error is never exposed to the user - // it is caught below, and the original error is thrown - throw new Error('The path is not a directory') - } - } catch { - throw error - } - } - } - - return make(path.resolve(input)) + return fs.mkdirSync(dir, { + mode: getMode(options), + recursive: true + }) } -module.exports.makeDirSync = (input, options) => { - checkPath(input) - options = processOptions(options) - if (useNativeRecursiveOption) { - const pth = path.resolve(input) - - return fs.mkdirSync(pth, { - mode: options.mode, - recursive: true - }) - } +/***/ }), - const make = pth => { - try { - fs.mkdirSync(pth, options.mode) - } catch (error) { - if (error.code === 'EPERM') { - throw error - } +/***/ 9907: +/***/ ((module, __unused_webpack_exports, __webpack_require__) => { - if (error.code === 'ENOENT') { - if (path.dirname(pth) === pth) { - throw permissionError(pth) - } +"use strict"; +// Adapted from https://github.com/sindresorhus/make-dir +// Copyright (c) Sindre Sorhus (sindresorhus.com) +// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: +// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - if (error.message.includes('null bytes')) { - throw error - } +const path = __webpack_require__(5622) - make(path.dirname(pth)) - return make(pth) - } +// https://github.com/nodejs/node/issues/8987 +// https://github.com/libuv/libuv/pull/1088 +module.exports.checkPath = function checkPath (pth) { + if (process.platform === 'win32') { + const pathHasInvalidWinCharacters = /[<>:"|?*]/.test(pth.replace(path.parse(pth).root, '')) - try { - if (!fs.statSync(pth).isDirectory()) { - // This error is never exposed to the user - // it is caught below, and the original error is thrown - throw new Error('The path is not a directory') - } - } catch { - throw error - } + if (pathHasInvalidWinCharacters) { + const error = new Error(`Path contains invalid characters: ${pth}`) + error.code = 'EINVAL' + throw error } } - - return make(path.resolve(input)) } @@ -3569,13 +3465,20 @@ function moveSync (src, dest, opts) { opts = opts || {} const overwrite = opts.overwrite || opts.clobber || false - const { srcStat } = stat.checkPathsSync(src, dest, 'move') + const { srcStat, isChangingCase = false } = stat.checkPathsSync(src, dest, 'move', opts) stat.checkParentPathsSync(src, srcStat, dest, 'move') - mkdirpSync(path.dirname(dest)) - return doRename(src, dest, overwrite) + if (!isParentRoot(dest)) mkdirpSync(path.dirname(dest)) + return doRename(src, dest, overwrite, isChangingCase) +} + +function isParentRoot (dest) { + const parent = path.dirname(dest) + const parsedPath = path.parse(parent) + return parsedPath.root === parent } -function doRename (src, dest, overwrite) { +function doRename (src, dest, overwrite, isChangingCase) { + if (isChangingCase) return rename(src, dest, overwrite) if (overwrite) { removeSync(dest) return rename(src, dest, overwrite) @@ -3643,20 +3546,28 @@ function move (src, dest, opts, cb) { const overwrite = opts.overwrite || opts.clobber || false - stat.checkPaths(src, dest, 'move', (err, stats) => { + stat.checkPaths(src, dest, 'move', opts, (err, stats) => { if (err) return cb(err) - const { srcStat } = stats + const { srcStat, isChangingCase = false } = stats stat.checkParentPaths(src, srcStat, dest, 'move', err => { if (err) return cb(err) + if (isParentRoot(dest)) return doRename(src, dest, overwrite, isChangingCase, cb) mkdirp(path.dirname(dest), err => { if (err) return cb(err) - return doRename(src, dest, overwrite, cb) + return doRename(src, dest, overwrite, isChangingCase, cb) }) }) }) } -function doRename (src, dest, overwrite, cb) { +function isParentRoot (dest) { + const parent = path.dirname(dest) + const parsedPath = path.parse(parent) + return parsedPath.root === parent +} + +function doRename (src, dest, overwrite, isChangingCase, cb) { + if (isChangingCase) return rename(src, dest, overwrite, cb) if (overwrite) { return remove(dest, err => { if (err) return cb(err) @@ -3768,12 +3679,25 @@ module.exports = { "use strict"; +const fs = __webpack_require__(7758) const u = __webpack_require__(9046).fromCallback const rimraf = __webpack_require__(8761) +function remove (path, callback) { + // Node 14.14.0+ + if (fs.rm) return fs.rm(path, { recursive: true, force: true }, callback) + rimraf(path, callback) +} + +function removeSync (path) { + // Node 14.14.0+ + if (fs.rmSync) return fs.rmSync(path, { recursive: true, force: true }) + rimraf.sync(path) +} + module.exports = { - remove: u(rimraf), - removeSync: rimraf.sync + remove: u(remove), + removeSync } @@ -4098,27 +4022,28 @@ rimraf.sync = rimrafSync const fs = __webpack_require__(1176) const path = __webpack_require__(5622) const util = __webpack_require__(1669) -const atLeastNode = __webpack_require__(5995) -const nodeSupportsBigInt = atLeastNode('10.5.0') -const stat = (file) => nodeSupportsBigInt ? fs.stat(file, { bigint: true }) : fs.stat(file) -const statSync = (file) => nodeSupportsBigInt ? fs.statSync(file, { bigint: true }) : fs.statSync(file) - -function getStats (src, dest) { +function getStats (src, dest, opts) { + const statFunc = opts.dereference + ? (file) => fs.stat(file, { bigint: true }) + : (file) => fs.lstat(file, { bigint: true }) return Promise.all([ - stat(src), - stat(dest).catch(err => { + statFunc(src), + statFunc(dest).catch(err => { if (err.code === 'ENOENT') return null throw err }) ]).then(([srcStat, destStat]) => ({ srcStat, destStat })) } -function getStatsSync (src, dest) { +function getStatsSync (src, dest, opts) { let destStat - const srcStat = statSync(src) + const statFunc = opts.dereference + ? (file) => fs.statSync(file, { bigint: true }) + : (file) => fs.lstatSync(file, { bigint: true }) + const srcStat = statFunc(src) try { - destStat = statSync(dest) + destStat = statFunc(dest) } catch (err) { if (err.code === 'ENOENT') return { srcStat, destStat: null } throw err @@ -4126,13 +4051,30 @@ function getStatsSync (src, dest) { return { srcStat, destStat } } -function checkPaths (src, dest, funcName, cb) { - util.callbackify(getStats)(src, dest, (err, stats) => { +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 && areIdentical(srcStat, destStat)) { - return cb(new Error('Source and destination must not be the same.')) + + 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}'.`)) + } } + if (srcStat.isDirectory() && isSrcSubdir(src, dest)) { return cb(new Error(errMsg(src, dest, funcName))) } @@ -4140,11 +4082,28 @@ function checkPaths (src, dest, funcName, cb) { }) } -function checkPathsSync (src, dest, funcName) { - const { srcStat, destStat } = getStatsSync(src, dest) - if (destStat && areIdentical(srcStat, destStat)) { - throw new Error('Source and destination must not be the same.') +function checkPathsSync (src, dest, funcName, opts) { + const { srcStat, destStat } = getStatsSync(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() && !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}'.`) + } } + if (srcStat.isDirectory() && isSrcSubdir(src, dest)) { throw new Error(errMsg(src, dest, funcName)) } @@ -4159,7 +4118,7 @@ function checkParentPaths (src, srcStat, dest, funcName, cb) { const srcParent = path.resolve(path.dirname(src)) const destParent = path.resolve(path.dirname(dest)) if (destParent === srcParent || destParent === path.parse(destParent).root) return cb() - const callback = (err, destStat) => { + fs.stat(destParent, { bigint: true }, (err, destStat) => { if (err) { if (err.code === 'ENOENT') return cb() return cb(err) @@ -4168,9 +4127,7 @@ function checkParentPaths (src, srcStat, dest, funcName, cb) { return cb(new Error(errMsg(src, dest, funcName))) } return checkParentPaths(src, srcStat, destParent, funcName, cb) - } - if (nodeSupportsBigInt) fs.stat(destParent, { bigint: true }, callback) - else fs.stat(destParent, callback) + }) } function checkParentPathsSync (src, srcStat, dest, funcName) { @@ -4179,7 +4136,7 @@ function checkParentPathsSync (src, srcStat, dest, funcName) { if (destParent === srcParent || destParent === path.parse(destParent).root) return let destStat try { - destStat = statSync(destParent) + destStat = fs.statSync(destParent, { bigint: true }) } catch (err) { if (err.code === 'ENOENT') return throw err @@ -4191,26 +4148,7 @@ function checkParentPathsSync (src, srcStat, dest, funcName) { } function areIdentical (srcStat, destStat) { - if (destStat.ino && destStat.dev && destStat.ino === srcStat.ino && destStat.dev === srcStat.dev) { - if (nodeSupportsBigInt || destStat.ino < Number.MAX_SAFE_INTEGER) { - // definitive answer - return true - } - // Use additional heuristics if we can't use 'bigint'. - // Different 'ino' could be represented the same if they are >= Number.MAX_SAFE_INTEGER - // See issue 657 - if (destStat.size === srcStat.size && - destStat.mode === srcStat.mode && - destStat.nlink === srcStat.nlink && - destStat.atimeMs === srcStat.atimeMs && - destStat.mtimeMs === srcStat.mtimeMs && - destStat.ctimeMs === srcStat.ctimeMs && - destStat.birthtimeMs === srcStat.birthtimeMs) { - // heuristic answer - return true - } - } - return false + return destStat.ino && destStat.dev && destStat.ino === srcStat.ino && destStat.dev === srcStat.dev } // return true if dest is a subdir of src, otherwise false. @@ -4230,7 +4168,8 @@ module.exports = { checkPathsSync, checkParentPaths, checkParentPathsSync, - isSrcSubdir + isSrcSubdir, + areIdentical } diff --git a/package.json b/package.json index 01c7161e1cb..1379d2b2eaf 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "@actions/core": "^1.2.7", "@actions/exec": "^1.0.4", "addressparser": "^1.0.1", - "fs-extra": "^9.0.1" + "fs-extra": "^10.0.0" }, "devDependencies": { "@actions/io": "^1.0.2", diff --git a/yarn.lock b/yarn.lock index 2e60d23cf6e..81b6728869a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -41,11 +41,6 @@ addressparser@^1.0.1: resolved "https://registry.yarnpkg.com/addressparser/-/addressparser-1.0.1.tgz#47afbe1a2a9262191db6838e4fd1d39b40821746" integrity sha1-R6++GiqSYhkdtoOOT9HTm0CCF0Y= -at-least-node@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/at-least-node/-/at-least-node-1.0.0.tgz#602cd4b46e844ad4effc92a8011a3c46e0238dc2" - integrity sha512-+q/t7Ekv1EDY2l6Gda6LLiX14rU9TV20Wa3ofeQmwPFZbOMo9DXrLbOjFaaclkXKWidIaopwAObQDqwWtGUjqg== - commander@^2.19.0: version "2.20.3" resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.3.tgz#fd485e84c03eb4881c20722ba48035e8531aeb33" @@ -66,12 +61,11 @@ editorconfig@^0.15.0: semver "^5.6.0" sigmund "^1.0.1" -fs-extra@^9.0.1: - version "9.1.0" - resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-9.1.0.tgz#5954460c764a8da2094ba3554bf839e6b9a7c86d" - integrity sha512-hcg3ZmepS30/7BSFqRvoo3DOMQu7IjqxO5nCDt+zM9XWjb33Wg7ziNT+Qvqbuc3+gWpzO02JubVyk2G4Zvo1OQ== +fs-extra@^10.0.0: + version "10.0.0" + resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-10.0.0.tgz#9ff61b655dde53fb34a82df84bb214ce802e17c1" + integrity sha512-C5owb14u9eJwizKGdchcDUQeFtlSHHthBk8pbX9Vc1PFZrLombudjDnNns88aYslCyF6IY5SUw3Roz6xShcEIQ== dependencies: - at-least-node "^1.0.0" graceful-fs "^4.2.0" jsonfile "^6.0.1" universalify "^2.0.0"