@nocobase/plugin-backup-restore 1.6.33 → 1.6.34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/externalVersion.js +5 -5
- package/dist/node_modules/@hapi/topo/package.json +1 -1
- package/dist/node_modules/archiver/package.json +1 -1
- package/dist/node_modules/decompress/package.json +1 -1
- package/dist/node_modules/fs-extra/LICENSE +15 -0
- package/dist/node_modules/fs-extra/lib/copy/copy.js +232 -0
- package/dist/node_modules/fs-extra/lib/copy/index.js +6 -0
- package/dist/node_modules/fs-extra/lib/copy-sync/copy-sync.js +166 -0
- package/dist/node_modules/fs-extra/lib/copy-sync/index.js +5 -0
- package/dist/node_modules/fs-extra/lib/empty/index.js +48 -0
- package/dist/node_modules/fs-extra/lib/ensure/file.js +69 -0
- package/dist/node_modules/fs-extra/lib/ensure/index.js +23 -0
- package/dist/node_modules/fs-extra/lib/ensure/link.js +61 -0
- package/dist/node_modules/fs-extra/lib/ensure/symlink-paths.js +99 -0
- package/dist/node_modules/fs-extra/lib/ensure/symlink-type.js +31 -0
- package/dist/node_modules/fs-extra/lib/ensure/symlink.js +63 -0
- package/dist/node_modules/fs-extra/lib/fs/index.js +130 -0
- package/dist/node_modules/fs-extra/lib/index.js +1 -0
- package/dist/node_modules/fs-extra/lib/json/index.js +16 -0
- package/dist/node_modules/fs-extra/lib/json/jsonfile.js +11 -0
- package/dist/node_modules/fs-extra/lib/json/output-json-sync.js +12 -0
- package/dist/node_modules/fs-extra/lib/json/output-json.js +12 -0
- package/dist/node_modules/fs-extra/lib/mkdirs/index.js +14 -0
- package/dist/node_modules/fs-extra/lib/mkdirs/make-dir.js +141 -0
- package/dist/node_modules/fs-extra/lib/move/index.js +6 -0
- package/dist/node_modules/fs-extra/lib/move/move.js +65 -0
- package/dist/node_modules/fs-extra/lib/move-sync/index.js +5 -0
- package/dist/node_modules/fs-extra/lib/move-sync/move-sync.js +47 -0
- package/dist/node_modules/fs-extra/lib/output/index.js +40 -0
- package/dist/node_modules/fs-extra/lib/path-exists/index.js +12 -0
- package/dist/node_modules/fs-extra/lib/remove/index.js +9 -0
- package/dist/node_modules/fs-extra/lib/remove/rimraf.js +302 -0
- package/dist/node_modules/fs-extra/lib/util/stat.js +139 -0
- package/dist/node_modules/fs-extra/lib/util/utimes.js +26 -0
- package/dist/node_modules/fs-extra/package.json +1 -0
- package/dist/node_modules/moment/package.json +1 -1
- package/dist/node_modules/semver/package.json +1 -1
- package/dist/server/dumper.js +3 -3
- package/package.json +2 -2
- package/dist/node_modules/mkdirp/LICENSE +0 -21
- package/dist/node_modules/mkdirp/bin/cmd.js +0 -68
- package/dist/node_modules/mkdirp/index.js +0 -1
- package/dist/node_modules/mkdirp/lib/find-made.js +0 -29
- package/dist/node_modules/mkdirp/lib/mkdirp-manual.js +0 -64
- package/dist/node_modules/mkdirp/lib/mkdirp-native.js +0 -39
- package/dist/node_modules/mkdirp/lib/opts-arg.js +0 -23
- package/dist/node_modules/mkdirp/lib/path-arg.js +0 -29
- package/dist/node_modules/mkdirp/lib/use-native.js +0 -10
- package/dist/node_modules/mkdirp/package.json +0 -1
- package/dist/node_modules/mkdirp/readme.markdown +0 -266
package/dist/externalVersion.js
CHANGED
|
@@ -10,15 +10,15 @@
|
|
|
10
10
|
module.exports = {
|
|
11
11
|
"@ant-design/icons": "5.6.1",
|
|
12
12
|
"@formily/antd-v5": "1.1.9",
|
|
13
|
-
"@nocobase/client": "1.6.
|
|
13
|
+
"@nocobase/client": "1.6.34",
|
|
14
14
|
"antd": "5.12.8",
|
|
15
15
|
"file-saver": "2.0.5",
|
|
16
16
|
"react": "18.2.0",
|
|
17
|
-
"@nocobase/server": "1.6.
|
|
18
|
-
"@nocobase/utils": "1.6.
|
|
19
|
-
"@nocobase/database": "1.6.
|
|
17
|
+
"@nocobase/server": "1.6.34",
|
|
18
|
+
"@nocobase/utils": "1.6.34",
|
|
19
|
+
"@nocobase/database": "1.6.34",
|
|
20
20
|
"dayjs": "1.11.10",
|
|
21
21
|
"lodash": "4.17.21",
|
|
22
22
|
"react-i18next": "11.18.6",
|
|
23
|
-
"@nocobase/actions": "1.6.
|
|
23
|
+
"@nocobase/actions": "1.6.34"
|
|
24
24
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@hapi/topo","description":"Topological sorting with grouping support","version":"6.0.2","repository":"git://github.com/hapijs/topo","main":"lib/index.js","types":"lib/index.d.ts","files":["lib"],"keywords":["topological","sort","toposort","topsort"],"eslintConfig":{"extends":["plugin:@hapi/module"]},"dependencies":{"@hapi/hoek":"^11.0.2"},"devDependencies":{"@hapi/code":"^9.0.3","@hapi/eslint-plugin":"*","@hapi/lab":"^25.1.2","@types/node":"^17.0.31","typescript":"~4.6.4"},"scripts":{"test":"lab -a @hapi/code -t 100 -L -Y","test-cov-html":"lab -a @hapi/code -t 100 -L -r html -o coverage.html"},"license":"BSD-3-Clause","_lastModified":"2025-05-
|
|
1
|
+
{"name":"@hapi/topo","description":"Topological sorting with grouping support","version":"6.0.2","repository":"git://github.com/hapijs/topo","main":"lib/index.js","types":"lib/index.d.ts","files":["lib"],"keywords":["topological","sort","toposort","topsort"],"eslintConfig":{"extends":["plugin:@hapi/module"]},"dependencies":{"@hapi/hoek":"^11.0.2"},"devDependencies":{"@hapi/code":"^9.0.3","@hapi/eslint-plugin":"*","@hapi/lab":"^25.1.2","@types/node":"^17.0.31","typescript":"~4.6.4"},"scripts":{"test":"lab -a @hapi/code -t 100 -L -Y","test-cov-html":"lab -a @hapi/code -t 100 -L -r html -o coverage.html"},"license":"BSD-3-Clause","_lastModified":"2025-05-27T12:55:46.122Z"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"archiver","version":"5.3.2","description":"a streaming interface for archive generation","homepage":"https://github.com/archiverjs/node-archiver","author":{"name":"Chris Talkington","url":"http://christalkington.com/"},"repository":{"type":"git","url":"https://github.com/archiverjs/node-archiver.git"},"bugs":{"url":"https://github.com/archiverjs/node-archiver/issues"},"license":"MIT","main":"index.js","files":["index.js","lib"],"engines":{"node":">= 10"},"scripts":{"test":"mocha --reporter dot","bench":"node benchmark/simple/pack-zip.js"},"dependencies":{"archiver-utils":"^2.1.0","async":"^3.2.4","buffer-crc32":"^0.2.1","readable-stream":"^3.6.0","readdir-glob":"^1.1.2","tar-stream":"^2.2.0","zip-stream":"^4.1.0"},"devDependencies":{"archiver-jsdoc-theme":"^1.1.3","chai":"^4.3.7","jsdoc":"^3.6.4","mkdirp":"^2.1.5","mocha":"^9.0.2","rimraf":"^4.3.1","stream-bench":"^0.1.2","tar":"^6.1.13","yauzl":"^2.9.0"},"keywords":["archive","archiver","stream","zip","tar"],"publishConfig":{"registry":"https://registry.npmjs.org/"},"_lastModified":"2025-05-
|
|
1
|
+
{"name":"archiver","version":"5.3.2","description":"a streaming interface for archive generation","homepage":"https://github.com/archiverjs/node-archiver","author":{"name":"Chris Talkington","url":"http://christalkington.com/"},"repository":{"type":"git","url":"https://github.com/archiverjs/node-archiver.git"},"bugs":{"url":"https://github.com/archiverjs/node-archiver/issues"},"license":"MIT","main":"index.js","files":["index.js","lib"],"engines":{"node":">= 10"},"scripts":{"test":"mocha --reporter dot","bench":"node benchmark/simple/pack-zip.js"},"dependencies":{"archiver-utils":"^2.1.0","async":"^3.2.4","buffer-crc32":"^0.2.1","readable-stream":"^3.6.0","readdir-glob":"^1.1.2","tar-stream":"^2.2.0","zip-stream":"^4.1.0"},"devDependencies":{"archiver-jsdoc-theme":"^1.1.3","chai":"^4.3.7","jsdoc":"^3.6.4","mkdirp":"^2.1.5","mocha":"^9.0.2","rimraf":"^4.3.1","stream-bench":"^0.1.2","tar":"^6.1.13","yauzl":"^2.9.0"},"keywords":["archive","archiver","stream","zip","tar"],"publishConfig":{"registry":"https://registry.npmjs.org/"},"_lastModified":"2025-05-27T12:55:44.414Z"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"decompress","version":"4.2.1","description":"Extracting archives made easy","license":"MIT","repository":"kevva/decompress","author":{"name":"Kevin Mårtensson","email":"kevinmartensson@gmail.com","url":"github.com/kevva"},"engines":{"node":">=4"},"scripts":{"test":"xo && ava"},"files":["index.js"],"keywords":["bz2","bzip2","decompress","extract","tar","tar.bz","tar.gz","zip","unzip"],"dependencies":{"decompress-tar":"^4.0.0","decompress-tarbz2":"^4.0.0","decompress-targz":"^4.0.0","decompress-unzip":"^4.0.1","graceful-fs":"^4.1.10","make-dir":"^1.0.0","pify":"^2.3.0","strip-dirs":"^2.0.0"},"devDependencies":{"ava":"*","esm":"^3.2.25","is-jpg":"^1.0.0","path-exists":"^3.0.0","pify":"^2.3.0","rimraf":"^3.0.2","xo":"*"},"ava":{"require":["esm"]},"xo":{"rules":{"promise/prefer-await-to-then":"off"}},"_lastModified":"2025-05-
|
|
1
|
+
{"name":"decompress","version":"4.2.1","description":"Extracting archives made easy","license":"MIT","repository":"kevva/decompress","author":{"name":"Kevin Mårtensson","email":"kevinmartensson@gmail.com","url":"github.com/kevva"},"engines":{"node":">=4"},"scripts":{"test":"xo && ava"},"files":["index.js"],"keywords":["bz2","bzip2","decompress","extract","tar","tar.bz","tar.gz","zip","unzip"],"dependencies":{"decompress-tar":"^4.0.0","decompress-tarbz2":"^4.0.0","decompress-targz":"^4.0.0","decompress-unzip":"^4.0.1","graceful-fs":"^4.1.10","make-dir":"^1.0.0","pify":"^2.3.0","strip-dirs":"^2.0.0"},"devDependencies":{"ava":"*","esm":"^3.2.25","is-jpg":"^1.0.0","path-exists":"^3.0.0","pify":"^2.3.0","rimraf":"^3.0.2","xo":"*"},"ava":{"require":["esm"]},"xo":{"rules":{"promise/prefer-await-to-then":"off"}},"_lastModified":"2025-05-27T12:55:45.941Z"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
(The MIT License)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2011-2017 JP Richardson
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
|
|
6
|
+
(the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify,
|
|
7
|
+
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
11
|
+
|
|
12
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
|
13
|
+
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
|
|
14
|
+
OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
15
|
+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const fs = require('graceful-fs')
|
|
4
|
+
const path = require('path')
|
|
5
|
+
const mkdirs = require('../mkdirs').mkdirs
|
|
6
|
+
const pathExists = require('../path-exists').pathExists
|
|
7
|
+
const utimesMillis = require('../util/utimes').utimesMillis
|
|
8
|
+
const stat = require('../util/stat')
|
|
9
|
+
|
|
10
|
+
function copy (src, dest, opts, cb) {
|
|
11
|
+
if (typeof opts === 'function' && !cb) {
|
|
12
|
+
cb = opts
|
|
13
|
+
opts = {}
|
|
14
|
+
} else if (typeof opts === 'function') {
|
|
15
|
+
opts = { filter: opts }
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
cb = cb || function () {}
|
|
19
|
+
opts = opts || {}
|
|
20
|
+
|
|
21
|
+
opts.clobber = 'clobber' in opts ? !!opts.clobber : true // default to true for now
|
|
22
|
+
opts.overwrite = 'overwrite' in opts ? !!opts.overwrite : opts.clobber // overwrite falls back to clobber
|
|
23
|
+
|
|
24
|
+
// Warn about using preserveTimestamps on 32-bit node
|
|
25
|
+
if (opts.preserveTimestamps && process.arch === 'ia32') {
|
|
26
|
+
console.warn(`fs-extra: Using the preserveTimestamps option in 32-bit node is not recommended;\n
|
|
27
|
+
see https://github.com/jprichardson/node-fs-extra/issues/269`)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
stat.checkPaths(src, dest, 'copy', (err, stats) => {
|
|
31
|
+
if (err) return cb(err)
|
|
32
|
+
const { srcStat, destStat } = stats
|
|
33
|
+
stat.checkParentPaths(src, srcStat, dest, 'copy', err => {
|
|
34
|
+
if (err) return cb(err)
|
|
35
|
+
if (opts.filter) return handleFilter(checkParentDir, destStat, src, dest, opts, cb)
|
|
36
|
+
return checkParentDir(destStat, src, dest, opts, cb)
|
|
37
|
+
})
|
|
38
|
+
})
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function checkParentDir (destStat, src, dest, opts, cb) {
|
|
42
|
+
const destParent = path.dirname(dest)
|
|
43
|
+
pathExists(destParent, (err, dirExists) => {
|
|
44
|
+
if (err) return cb(err)
|
|
45
|
+
if (dirExists) return startCopy(destStat, src, dest, opts, cb)
|
|
46
|
+
mkdirs(destParent, err => {
|
|
47
|
+
if (err) return cb(err)
|
|
48
|
+
return startCopy(destStat, src, dest, opts, cb)
|
|
49
|
+
})
|
|
50
|
+
})
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function handleFilter (onInclude, destStat, src, dest, opts, cb) {
|
|
54
|
+
Promise.resolve(opts.filter(src, dest)).then(include => {
|
|
55
|
+
if (include) return onInclude(destStat, src, dest, opts, cb)
|
|
56
|
+
return cb()
|
|
57
|
+
}, error => cb(error))
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function startCopy (destStat, src, dest, opts, cb) {
|
|
61
|
+
if (opts.filter) return handleFilter(getStats, destStat, src, dest, opts, cb)
|
|
62
|
+
return getStats(destStat, src, dest, opts, cb)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function getStats (destStat, src, dest, opts, cb) {
|
|
66
|
+
const stat = opts.dereference ? fs.stat : fs.lstat
|
|
67
|
+
stat(src, (err, srcStat) => {
|
|
68
|
+
if (err) return cb(err)
|
|
69
|
+
|
|
70
|
+
if (srcStat.isDirectory()) return onDir(srcStat, destStat, src, dest, opts, cb)
|
|
71
|
+
else if (srcStat.isFile() ||
|
|
72
|
+
srcStat.isCharacterDevice() ||
|
|
73
|
+
srcStat.isBlockDevice()) return onFile(srcStat, destStat, src, dest, opts, cb)
|
|
74
|
+
else if (srcStat.isSymbolicLink()) return onLink(destStat, src, dest, opts, cb)
|
|
75
|
+
})
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function onFile (srcStat, destStat, src, dest, opts, cb) {
|
|
79
|
+
if (!destStat) return copyFile(srcStat, src, dest, opts, cb)
|
|
80
|
+
return mayCopyFile(srcStat, src, dest, opts, cb)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function mayCopyFile (srcStat, src, dest, opts, cb) {
|
|
84
|
+
if (opts.overwrite) {
|
|
85
|
+
fs.unlink(dest, err => {
|
|
86
|
+
if (err) return cb(err)
|
|
87
|
+
return copyFile(srcStat, src, dest, opts, cb)
|
|
88
|
+
})
|
|
89
|
+
} else if (opts.errorOnExist) {
|
|
90
|
+
return cb(new Error(`'${dest}' already exists`))
|
|
91
|
+
} else return cb()
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function copyFile (srcStat, src, dest, opts, cb) {
|
|
95
|
+
fs.copyFile(src, dest, err => {
|
|
96
|
+
if (err) return cb(err)
|
|
97
|
+
if (opts.preserveTimestamps) return handleTimestampsAndMode(srcStat.mode, src, dest, cb)
|
|
98
|
+
return setDestMode(dest, srcStat.mode, cb)
|
|
99
|
+
})
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function handleTimestampsAndMode (srcMode, src, dest, cb) {
|
|
103
|
+
// Make sure the file is writable before setting the timestamp
|
|
104
|
+
// otherwise open fails with EPERM when invoked with 'r+'
|
|
105
|
+
// (through utimes call)
|
|
106
|
+
if (fileIsNotWritable(srcMode)) {
|
|
107
|
+
return makeFileWritable(dest, srcMode, err => {
|
|
108
|
+
if (err) return cb(err)
|
|
109
|
+
return setDestTimestampsAndMode(srcMode, src, dest, cb)
|
|
110
|
+
})
|
|
111
|
+
}
|
|
112
|
+
return setDestTimestampsAndMode(srcMode, src, dest, cb)
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function fileIsNotWritable (srcMode) {
|
|
116
|
+
return (srcMode & 0o200) === 0
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function makeFileWritable (dest, srcMode, cb) {
|
|
120
|
+
return setDestMode(dest, srcMode | 0o200, cb)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function setDestTimestampsAndMode (srcMode, src, dest, cb) {
|
|
124
|
+
setDestTimestamps(src, dest, err => {
|
|
125
|
+
if (err) return cb(err)
|
|
126
|
+
return setDestMode(dest, srcMode, cb)
|
|
127
|
+
})
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function setDestMode (dest, srcMode, cb) {
|
|
131
|
+
return fs.chmod(dest, srcMode, cb)
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function setDestTimestamps (src, dest, cb) {
|
|
135
|
+
// The initial srcStat.atime cannot be trusted
|
|
136
|
+
// because it is modified by the read(2) system call
|
|
137
|
+
// (See https://nodejs.org/api/fs.html#fs_stat_time_values)
|
|
138
|
+
fs.stat(src, (err, updatedSrcStat) => {
|
|
139
|
+
if (err) return cb(err)
|
|
140
|
+
return utimesMillis(dest, updatedSrcStat.atime, updatedSrcStat.mtime, cb)
|
|
141
|
+
})
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function onDir (srcStat, destStat, src, dest, opts, cb) {
|
|
145
|
+
if (!destStat) return mkDirAndCopy(srcStat.mode, src, dest, opts, cb)
|
|
146
|
+
if (destStat && !destStat.isDirectory()) {
|
|
147
|
+
return cb(new Error(`Cannot overwrite non-directory '${dest}' with directory '${src}'.`))
|
|
148
|
+
}
|
|
149
|
+
return copyDir(src, dest, opts, cb)
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function mkDirAndCopy (srcMode, src, dest, opts, cb) {
|
|
153
|
+
fs.mkdir(dest, err => {
|
|
154
|
+
if (err) return cb(err)
|
|
155
|
+
copyDir(src, dest, opts, err => {
|
|
156
|
+
if (err) return cb(err)
|
|
157
|
+
return setDestMode(dest, srcMode, cb)
|
|
158
|
+
})
|
|
159
|
+
})
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function copyDir (src, dest, opts, cb) {
|
|
163
|
+
fs.readdir(src, (err, items) => {
|
|
164
|
+
if (err) return cb(err)
|
|
165
|
+
return copyDirItems(items, src, dest, opts, cb)
|
|
166
|
+
})
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function copyDirItems (items, src, dest, opts, cb) {
|
|
170
|
+
const item = items.pop()
|
|
171
|
+
if (!item) return cb()
|
|
172
|
+
return copyDirItem(items, item, src, dest, opts, cb)
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function copyDirItem (items, item, src, dest, opts, cb) {
|
|
176
|
+
const srcItem = path.join(src, item)
|
|
177
|
+
const destItem = path.join(dest, item)
|
|
178
|
+
stat.checkPaths(srcItem, destItem, 'copy', (err, stats) => {
|
|
179
|
+
if (err) return cb(err)
|
|
180
|
+
const { destStat } = stats
|
|
181
|
+
startCopy(destStat, srcItem, destItem, opts, err => {
|
|
182
|
+
if (err) return cb(err)
|
|
183
|
+
return copyDirItems(items, src, dest, opts, cb)
|
|
184
|
+
})
|
|
185
|
+
})
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function onLink (destStat, src, dest, opts, cb) {
|
|
189
|
+
fs.readlink(src, (err, resolvedSrc) => {
|
|
190
|
+
if (err) return cb(err)
|
|
191
|
+
if (opts.dereference) {
|
|
192
|
+
resolvedSrc = path.resolve(process.cwd(), resolvedSrc)
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
if (!destStat) {
|
|
196
|
+
return fs.symlink(resolvedSrc, dest, cb)
|
|
197
|
+
} else {
|
|
198
|
+
fs.readlink(dest, (err, resolvedDest) => {
|
|
199
|
+
if (err) {
|
|
200
|
+
// dest exists and is a regular file or directory,
|
|
201
|
+
// Windows may throw UNKNOWN error. If dest already exists,
|
|
202
|
+
// fs throws error anyway, so no need to guard against it here.
|
|
203
|
+
if (err.code === 'EINVAL' || err.code === 'UNKNOWN') return fs.symlink(resolvedSrc, dest, cb)
|
|
204
|
+
return cb(err)
|
|
205
|
+
}
|
|
206
|
+
if (opts.dereference) {
|
|
207
|
+
resolvedDest = path.resolve(process.cwd(), resolvedDest)
|
|
208
|
+
}
|
|
209
|
+
if (stat.isSrcSubdir(resolvedSrc, resolvedDest)) {
|
|
210
|
+
return cb(new Error(`Cannot copy '${resolvedSrc}' to a subdirectory of itself, '${resolvedDest}'.`))
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// do not copy if src is a subdir of dest since unlinking
|
|
214
|
+
// dest in this case would result in removing src contents
|
|
215
|
+
// and therefore a broken symlink would be created.
|
|
216
|
+
if (destStat.isDirectory() && stat.isSrcSubdir(resolvedDest, resolvedSrc)) {
|
|
217
|
+
return cb(new Error(`Cannot overwrite '${resolvedDest}' with '${resolvedSrc}'.`))
|
|
218
|
+
}
|
|
219
|
+
return copyLink(resolvedSrc, dest, cb)
|
|
220
|
+
})
|
|
221
|
+
}
|
|
222
|
+
})
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
function copyLink (resolvedSrc, dest, cb) {
|
|
226
|
+
fs.unlink(dest, err => {
|
|
227
|
+
if (err) return cb(err)
|
|
228
|
+
return fs.symlink(resolvedSrc, dest, cb)
|
|
229
|
+
})
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
module.exports = copy
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const fs = require('graceful-fs')
|
|
4
|
+
const path = require('path')
|
|
5
|
+
const mkdirsSync = require('../mkdirs').mkdirsSync
|
|
6
|
+
const utimesMillisSync = require('../util/utimes').utimesMillisSync
|
|
7
|
+
const stat = require('../util/stat')
|
|
8
|
+
|
|
9
|
+
function copySync (src, dest, opts) {
|
|
10
|
+
if (typeof opts === 'function') {
|
|
11
|
+
opts = { filter: opts }
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
opts = opts || {}
|
|
15
|
+
opts.clobber = 'clobber' in opts ? !!opts.clobber : true // default to true for now
|
|
16
|
+
opts.overwrite = 'overwrite' in opts ? !!opts.overwrite : opts.clobber // overwrite falls back to clobber
|
|
17
|
+
|
|
18
|
+
// Warn about using preserveTimestamps on 32-bit node
|
|
19
|
+
if (opts.preserveTimestamps && process.arch === 'ia32') {
|
|
20
|
+
console.warn(`fs-extra: Using the preserveTimestamps option in 32-bit node is not recommended;\n
|
|
21
|
+
see https://github.com/jprichardson/node-fs-extra/issues/269`)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const { srcStat, destStat } = stat.checkPathsSync(src, dest, 'copy')
|
|
25
|
+
stat.checkParentPathsSync(src, srcStat, dest, 'copy')
|
|
26
|
+
return handleFilterAndCopy(destStat, src, dest, opts)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function handleFilterAndCopy (destStat, src, dest, opts) {
|
|
30
|
+
if (opts.filter && !opts.filter(src, dest)) return
|
|
31
|
+
const destParent = path.dirname(dest)
|
|
32
|
+
if (!fs.existsSync(destParent)) mkdirsSync(destParent)
|
|
33
|
+
return startCopy(destStat, src, dest, opts)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function startCopy (destStat, src, dest, opts) {
|
|
37
|
+
if (opts.filter && !opts.filter(src, dest)) return
|
|
38
|
+
return getStats(destStat, src, dest, opts)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function getStats (destStat, src, dest, opts) {
|
|
42
|
+
const statSync = opts.dereference ? fs.statSync : fs.lstatSync
|
|
43
|
+
const srcStat = statSync(src)
|
|
44
|
+
|
|
45
|
+
if (srcStat.isDirectory()) return onDir(srcStat, destStat, src, dest, opts)
|
|
46
|
+
else if (srcStat.isFile() ||
|
|
47
|
+
srcStat.isCharacterDevice() ||
|
|
48
|
+
srcStat.isBlockDevice()) return onFile(srcStat, destStat, src, dest, opts)
|
|
49
|
+
else if (srcStat.isSymbolicLink()) return onLink(destStat, src, dest, opts)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function onFile (srcStat, destStat, src, dest, opts) {
|
|
53
|
+
if (!destStat) return copyFile(srcStat, src, dest, opts)
|
|
54
|
+
return mayCopyFile(srcStat, src, dest, opts)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function mayCopyFile (srcStat, src, dest, opts) {
|
|
58
|
+
if (opts.overwrite) {
|
|
59
|
+
fs.unlinkSync(dest)
|
|
60
|
+
return copyFile(srcStat, src, dest, opts)
|
|
61
|
+
} else if (opts.errorOnExist) {
|
|
62
|
+
throw new Error(`'${dest}' already exists`)
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function copyFile (srcStat, src, dest, opts) {
|
|
67
|
+
fs.copyFileSync(src, dest)
|
|
68
|
+
if (opts.preserveTimestamps) handleTimestamps(srcStat.mode, src, dest)
|
|
69
|
+
return setDestMode(dest, srcStat.mode)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function handleTimestamps (srcMode, src, dest) {
|
|
73
|
+
// Make sure the file is writable before setting the timestamp
|
|
74
|
+
// otherwise open fails with EPERM when invoked with 'r+'
|
|
75
|
+
// (through utimes call)
|
|
76
|
+
if (fileIsNotWritable(srcMode)) makeFileWritable(dest, srcMode)
|
|
77
|
+
return setDestTimestamps(src, dest)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function fileIsNotWritable (srcMode) {
|
|
81
|
+
return (srcMode & 0o200) === 0
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function makeFileWritable (dest, srcMode) {
|
|
85
|
+
return setDestMode(dest, srcMode | 0o200)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function setDestMode (dest, srcMode) {
|
|
89
|
+
return fs.chmodSync(dest, srcMode)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function setDestTimestamps (src, dest) {
|
|
93
|
+
// The initial srcStat.atime cannot be trusted
|
|
94
|
+
// because it is modified by the read(2) system call
|
|
95
|
+
// (See https://nodejs.org/api/fs.html#fs_stat_time_values)
|
|
96
|
+
const updatedSrcStat = fs.statSync(src)
|
|
97
|
+
return utimesMillisSync(dest, updatedSrcStat.atime, updatedSrcStat.mtime)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function onDir (srcStat, destStat, src, dest, opts) {
|
|
101
|
+
if (!destStat) return mkDirAndCopy(srcStat.mode, src, dest, opts)
|
|
102
|
+
if (destStat && !destStat.isDirectory()) {
|
|
103
|
+
throw new Error(`Cannot overwrite non-directory '${dest}' with directory '${src}'.`)
|
|
104
|
+
}
|
|
105
|
+
return copyDir(src, dest, opts)
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function mkDirAndCopy (srcMode, src, dest, opts) {
|
|
109
|
+
fs.mkdirSync(dest)
|
|
110
|
+
copyDir(src, dest, opts)
|
|
111
|
+
return setDestMode(dest, srcMode)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function copyDir (src, dest, opts) {
|
|
115
|
+
fs.readdirSync(src).forEach(item => copyDirItem(item, src, dest, opts))
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function copyDirItem (item, src, dest, opts) {
|
|
119
|
+
const srcItem = path.join(src, item)
|
|
120
|
+
const destItem = path.join(dest, item)
|
|
121
|
+
const { destStat } = stat.checkPathsSync(srcItem, destItem, 'copy')
|
|
122
|
+
return startCopy(destStat, srcItem, destItem, opts)
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function onLink (destStat, src, dest, opts) {
|
|
126
|
+
let resolvedSrc = fs.readlinkSync(src)
|
|
127
|
+
if (opts.dereference) {
|
|
128
|
+
resolvedSrc = path.resolve(process.cwd(), resolvedSrc)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (!destStat) {
|
|
132
|
+
return fs.symlinkSync(resolvedSrc, dest)
|
|
133
|
+
} else {
|
|
134
|
+
let resolvedDest
|
|
135
|
+
try {
|
|
136
|
+
resolvedDest = fs.readlinkSync(dest)
|
|
137
|
+
} catch (err) {
|
|
138
|
+
// dest exists and is a regular file or directory,
|
|
139
|
+
// Windows may throw UNKNOWN error. If dest already exists,
|
|
140
|
+
// fs throws error anyway, so no need to guard against it here.
|
|
141
|
+
if (err.code === 'EINVAL' || err.code === 'UNKNOWN') return fs.symlinkSync(resolvedSrc, dest)
|
|
142
|
+
throw err
|
|
143
|
+
}
|
|
144
|
+
if (opts.dereference) {
|
|
145
|
+
resolvedDest = path.resolve(process.cwd(), resolvedDest)
|
|
146
|
+
}
|
|
147
|
+
if (stat.isSrcSubdir(resolvedSrc, resolvedDest)) {
|
|
148
|
+
throw new Error(`Cannot copy '${resolvedSrc}' to a subdirectory of itself, '${resolvedDest}'.`)
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// prevent copy if src is a subdir of dest since unlinking
|
|
152
|
+
// dest in this case would result in removing src contents
|
|
153
|
+
// and therefore a broken symlink would be created.
|
|
154
|
+
if (fs.statSync(dest).isDirectory() && stat.isSrcSubdir(resolvedDest, resolvedSrc)) {
|
|
155
|
+
throw new Error(`Cannot overwrite '${resolvedDest}' with '${resolvedSrc}'.`)
|
|
156
|
+
}
|
|
157
|
+
return copyLink(resolvedSrc, dest)
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function copyLink (resolvedSrc, dest) {
|
|
162
|
+
fs.unlinkSync(dest)
|
|
163
|
+
return fs.symlinkSync(resolvedSrc, dest)
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
module.exports = copySync
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const u = require('universalify').fromCallback
|
|
4
|
+
const fs = require('graceful-fs')
|
|
5
|
+
const path = require('path')
|
|
6
|
+
const mkdir = require('../mkdirs')
|
|
7
|
+
const remove = require('../remove')
|
|
8
|
+
|
|
9
|
+
const emptyDir = u(function emptyDir (dir, callback) {
|
|
10
|
+
callback = callback || function () {}
|
|
11
|
+
fs.readdir(dir, (err, items) => {
|
|
12
|
+
if (err) return mkdir.mkdirs(dir, callback)
|
|
13
|
+
|
|
14
|
+
items = items.map(item => path.join(dir, item))
|
|
15
|
+
|
|
16
|
+
deleteItem()
|
|
17
|
+
|
|
18
|
+
function deleteItem () {
|
|
19
|
+
const item = items.pop()
|
|
20
|
+
if (!item) return callback()
|
|
21
|
+
remove.remove(item, err => {
|
|
22
|
+
if (err) return callback(err)
|
|
23
|
+
deleteItem()
|
|
24
|
+
})
|
|
25
|
+
}
|
|
26
|
+
})
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
function emptyDirSync (dir) {
|
|
30
|
+
let items
|
|
31
|
+
try {
|
|
32
|
+
items = fs.readdirSync(dir)
|
|
33
|
+
} catch {
|
|
34
|
+
return mkdir.mkdirsSync(dir)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
items.forEach(item => {
|
|
38
|
+
item = path.join(dir, item)
|
|
39
|
+
remove.removeSync(item)
|
|
40
|
+
})
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
module.exports = {
|
|
44
|
+
emptyDirSync,
|
|
45
|
+
emptydirSync: emptyDirSync,
|
|
46
|
+
emptyDir,
|
|
47
|
+
emptydir: emptyDir
|
|
48
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const u = require('universalify').fromCallback
|
|
4
|
+
const path = require('path')
|
|
5
|
+
const fs = require('graceful-fs')
|
|
6
|
+
const mkdir = require('../mkdirs')
|
|
7
|
+
|
|
8
|
+
function createFile (file, callback) {
|
|
9
|
+
function makeFile () {
|
|
10
|
+
fs.writeFile(file, '', err => {
|
|
11
|
+
if (err) return callback(err)
|
|
12
|
+
callback()
|
|
13
|
+
})
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
fs.stat(file, (err, stats) => { // eslint-disable-line handle-callback-err
|
|
17
|
+
if (!err && stats.isFile()) return callback()
|
|
18
|
+
const dir = path.dirname(file)
|
|
19
|
+
fs.stat(dir, (err, stats) => {
|
|
20
|
+
if (err) {
|
|
21
|
+
// if the directory doesn't exist, make it
|
|
22
|
+
if (err.code === 'ENOENT') {
|
|
23
|
+
return mkdir.mkdirs(dir, err => {
|
|
24
|
+
if (err) return callback(err)
|
|
25
|
+
makeFile()
|
|
26
|
+
})
|
|
27
|
+
}
|
|
28
|
+
return callback(err)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (stats.isDirectory()) makeFile()
|
|
32
|
+
else {
|
|
33
|
+
// parent is not a directory
|
|
34
|
+
// This is just to cause an internal ENOTDIR error to be thrown
|
|
35
|
+
fs.readdir(dir, err => {
|
|
36
|
+
if (err) return callback(err)
|
|
37
|
+
})
|
|
38
|
+
}
|
|
39
|
+
})
|
|
40
|
+
})
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function createFileSync (file) {
|
|
44
|
+
let stats
|
|
45
|
+
try {
|
|
46
|
+
stats = fs.statSync(file)
|
|
47
|
+
} catch {}
|
|
48
|
+
if (stats && stats.isFile()) return
|
|
49
|
+
|
|
50
|
+
const dir = path.dirname(file)
|
|
51
|
+
try {
|
|
52
|
+
if (!fs.statSync(dir).isDirectory()) {
|
|
53
|
+
// parent is not a directory
|
|
54
|
+
// This is just to cause an internal ENOTDIR error to be thrown
|
|
55
|
+
fs.readdirSync(dir)
|
|
56
|
+
}
|
|
57
|
+
} catch (err) {
|
|
58
|
+
// If the stat call above failed because the directory doesn't exist, create it
|
|
59
|
+
if (err && err.code === 'ENOENT') mkdir.mkdirsSync(dir)
|
|
60
|
+
else throw err
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
fs.writeFileSync(file, '')
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
module.exports = {
|
|
67
|
+
createFile: u(createFile),
|
|
68
|
+
createFileSync
|
|
69
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const file = require('./file')
|
|
4
|
+
const link = require('./link')
|
|
5
|
+
const symlink = require('./symlink')
|
|
6
|
+
|
|
7
|
+
module.exports = {
|
|
8
|
+
// file
|
|
9
|
+
createFile: file.createFile,
|
|
10
|
+
createFileSync: file.createFileSync,
|
|
11
|
+
ensureFile: file.createFile,
|
|
12
|
+
ensureFileSync: file.createFileSync,
|
|
13
|
+
// link
|
|
14
|
+
createLink: link.createLink,
|
|
15
|
+
createLinkSync: link.createLinkSync,
|
|
16
|
+
ensureLink: link.createLink,
|
|
17
|
+
ensureLinkSync: link.createLinkSync,
|
|
18
|
+
// symlink
|
|
19
|
+
createSymlink: symlink.createSymlink,
|
|
20
|
+
createSymlinkSync: symlink.createSymlinkSync,
|
|
21
|
+
ensureSymlink: symlink.createSymlink,
|
|
22
|
+
ensureSymlinkSync: symlink.createSymlinkSync
|
|
23
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const u = require('universalify').fromCallback
|
|
4
|
+
const path = require('path')
|
|
5
|
+
const fs = require('graceful-fs')
|
|
6
|
+
const mkdir = require('../mkdirs')
|
|
7
|
+
const pathExists = require('../path-exists').pathExists
|
|
8
|
+
|
|
9
|
+
function createLink (srcpath, dstpath, callback) {
|
|
10
|
+
function makeLink (srcpath, dstpath) {
|
|
11
|
+
fs.link(srcpath, dstpath, err => {
|
|
12
|
+
if (err) return callback(err)
|
|
13
|
+
callback(null)
|
|
14
|
+
})
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
pathExists(dstpath, (err, destinationExists) => {
|
|
18
|
+
if (err) return callback(err)
|
|
19
|
+
if (destinationExists) return callback(null)
|
|
20
|
+
fs.lstat(srcpath, (err) => {
|
|
21
|
+
if (err) {
|
|
22
|
+
err.message = err.message.replace('lstat', 'ensureLink')
|
|
23
|
+
return callback(err)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const dir = path.dirname(dstpath)
|
|
27
|
+
pathExists(dir, (err, dirExists) => {
|
|
28
|
+
if (err) return callback(err)
|
|
29
|
+
if (dirExists) return makeLink(srcpath, dstpath)
|
|
30
|
+
mkdir.mkdirs(dir, err => {
|
|
31
|
+
if (err) return callback(err)
|
|
32
|
+
makeLink(srcpath, dstpath)
|
|
33
|
+
})
|
|
34
|
+
})
|
|
35
|
+
})
|
|
36
|
+
})
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function createLinkSync (srcpath, dstpath) {
|
|
40
|
+
const destinationExists = fs.existsSync(dstpath)
|
|
41
|
+
if (destinationExists) return undefined
|
|
42
|
+
|
|
43
|
+
try {
|
|
44
|
+
fs.lstatSync(srcpath)
|
|
45
|
+
} catch (err) {
|
|
46
|
+
err.message = err.message.replace('lstat', 'ensureLink')
|
|
47
|
+
throw err
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const dir = path.dirname(dstpath)
|
|
51
|
+
const dirExists = fs.existsSync(dir)
|
|
52
|
+
if (dirExists) return fs.linkSync(srcpath, dstpath)
|
|
53
|
+
mkdir.mkdirsSync(dir)
|
|
54
|
+
|
|
55
|
+
return fs.linkSync(srcpath, dstpath)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
module.exports = {
|
|
59
|
+
createLink: u(createLink),
|
|
60
|
+
createLinkSync
|
|
61
|
+
}
|