@xen-orchestra/fs 0.20.0 → 1.0.2

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/cli.js ADDED
@@ -0,0 +1,62 @@
1
+ #!/usr/bin/env node
2
+
3
+ 'use strict'
4
+
5
+ const Disposable = require('promise-toolbox/Disposable')
6
+ const { getBoundPropertyDescriptor } = require('bind-property-descriptor')
7
+
8
+ const { getSyncedHandler } = require('./')
9
+
10
+ const { getPrototypeOf, ownKeys } = Reflect
11
+ function getAllBoundDescriptors(object) {
12
+ const descriptors = { __proto__: null }
13
+ let current = object
14
+ do {
15
+ ownKeys(current).forEach(key => {
16
+ if (!(key in descriptors)) {
17
+ descriptors[key] = getBoundPropertyDescriptor(current, key, object)
18
+ }
19
+ })
20
+ } while ((current = getPrototypeOf(current)) !== null)
21
+ return descriptors
22
+ }
23
+
24
+ // https://gist.github.com/julien-f/18161f6032e808d6fa08782951ce3bfb
25
+ async function repl({ prompt, context } = {}) {
26
+ const repl = require('repl').start({
27
+ ignoreUndefined: true,
28
+ prompt,
29
+ })
30
+ if (context !== undefined) {
31
+ Object.defineProperties(repl.context, Object.getOwnPropertyDescriptors(context))
32
+ }
33
+ const { eval: evaluate } = repl
34
+ repl.eval = (cmd, context, filename, cb) => {
35
+ evaluate.call(repl, cmd, context, filename, (error, result) => {
36
+ if (error != null) {
37
+ return cb(error)
38
+ }
39
+ Promise.resolve(result).then(result => cb(undefined, result), cb)
40
+ })
41
+ }
42
+ return new Promise((resolve, reject) => {
43
+ repl.on('error', reject).on('exit', resolve)
44
+ })
45
+ }
46
+
47
+ async function* main([url]) {
48
+ if (url === undefined) {
49
+ throw new TypeError('missing arg <url>')
50
+ }
51
+
52
+ const handler = yield getSyncedHandler({ url })
53
+ await repl({
54
+ prompt: handler.type + '> ',
55
+ context: Object.create(null, getAllBoundDescriptors(handler)),
56
+ })
57
+ }
58
+
59
+ Disposable.wrap(main)(process.argv.slice(2)).catch(error => {
60
+ console.error('FATAL:', error)
61
+ process.exitCode = 1
62
+ })
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = copyStreamToBuffer;
7
+
8
+ function copyStreamToBuffer(inputStream, destinationBuffer) {
9
+ return new Promise((resolve, reject) => {
10
+ let index = 0;
11
+ inputStream.on('data', chunk => {
12
+ chunk.copy(destinationBuffer, index);
13
+ index += chunk.length;
14
+ });
15
+ inputStream.on('end', () => resolve(index));
16
+ inputStream.on('error', err => reject(err));
17
+ });
18
+ }
19
+ //# sourceMappingURL=_copyStreamToBuffer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_copyStreamToBuffer.js","names":["copyStreamToBuffer","inputStream","destinationBuffer","Promise","resolve","reject","index","on","chunk","copy","length","err"],"sources":["../src/_copyStreamToBuffer.js"],"sourcesContent":["/**\n * @param {Readable} inputStream\n * @param {Buffer} destinationBuffer\n * @returns {Promise<int>} Buffer length\n * @private\n */\nexport default function copyStreamToBuffer(inputStream, destinationBuffer) {\n return new Promise((resolve, reject) => {\n let index = 0\n\n inputStream.on('data', chunk => {\n chunk.copy(destinationBuffer, index)\n index += chunk.length\n })\n inputStream.on('end', () => resolve(index))\n inputStream.on('error', err => reject(err))\n })\n}\n"],"mappings":";;;;;;;AAMe,SAASA,kBAAT,CAA4BC,WAA5B,EAAyCC,iBAAzC,EAA4D;EACzE,OAAO,IAAIC,OAAJ,CAAY,CAACC,OAAD,EAAUC,MAAV,KAAqB;IACtC,IAAIC,KAAK,GAAG,CAAZ;IAEAL,WAAW,CAACM,EAAZ,CAAe,MAAf,EAAuBC,KAAK,IAAI;MAC9BA,KAAK,CAACC,IAAN,CAAWP,iBAAX,EAA8BI,KAA9B;MACAA,KAAK,IAAIE,KAAK,CAACE,MAAf;IACD,CAHD;IAIAT,WAAW,CAACM,EAAZ,CAAe,KAAf,EAAsB,MAAMH,OAAO,CAACE,KAAD,CAAnC;IACAL,WAAW,CAACM,EAAZ,CAAe,OAAf,EAAwBI,GAAG,IAAIN,MAAM,CAACM,GAAD,CAArC;EACD,CATM,CAAP;AAUD"}
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = createBufferFromStream;
7
+
8
+ function createBufferFromStream(stream) {
9
+ return new Promise((resolve, reject) => {
10
+ const chunks = [];
11
+ stream.on('data', chunk => chunks.push(chunk));
12
+ stream.on('end', () => resolve(Buffer.concat(chunks)));
13
+ stream.on('error', error => reject(error));
14
+ });
15
+ }
16
+ //# sourceMappingURL=_createBufferFromStream.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_createBufferFromStream.js","names":["createBufferFromStream","stream","Promise","resolve","reject","chunks","on","chunk","push","Buffer","concat","error"],"sources":["../src/_createBufferFromStream.js"],"sourcesContent":["/**\n * @param {Readable} stream\n * @returns {Promise<Buffer>}\n * @private\n */\nexport default function createBufferFromStream(stream) {\n return new Promise((resolve, reject) => {\n const chunks = []\n stream.on('data', chunk => chunks.push(chunk))\n stream.on('end', () => resolve(Buffer.concat(chunks)))\n stream.on('error', error => reject(error))\n })\n}\n"],"mappings":";;;;;;;AAKe,SAASA,sBAAT,CAAgCC,MAAhC,EAAwC;EACrD,OAAO,IAAIC,OAAJ,CAAY,CAACC,OAAD,EAAUC,MAAV,KAAqB;IACtC,MAAMC,MAAM,GAAG,EAAf;IACAJ,MAAM,CAACK,EAAP,CAAU,MAAV,EAAkBC,KAAK,IAAIF,MAAM,CAACG,IAAP,CAAYD,KAAZ,CAA3B;IACAN,MAAM,CAACK,EAAP,CAAU,KAAV,EAAiB,MAAMH,OAAO,CAACM,MAAM,CAACC,MAAP,CAAcL,MAAd,CAAD,CAA9B;IACAJ,MAAM,CAACK,EAAP,CAAU,OAAV,EAAmBK,KAAK,IAAIP,MAAM,CAACO,KAAD,CAAlC;EACD,CALM,CAAP;AAMD"}
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = guessAwsRegion;
7
+
8
+ function guessAwsRegion(host) {
9
+ const matches = /^s3\.([^.]+)\.amazonaws.com$/.exec(host);
10
+ return matches !== null ? matches[1] : 'us-east-1';
11
+ }
12
+ //# sourceMappingURL=_guessAwsRegion.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_guessAwsRegion.js","names":["guessAwsRegion","host","matches","exec"],"sources":["../src/_guessAwsRegion.js"],"sourcesContent":["export default function guessAwsRegion(host) {\n const matches = /^s3\\.([^.]+)\\.amazonaws.com$/.exec(host)\n return matches !== null ? matches[1] : 'us-east-1'\n}\n"],"mappings":";;;;;;;AAAe,SAASA,cAAT,CAAwBC,IAAxB,EAA8B;EAC3C,MAAMC,OAAO,GAAG,+BAA+BC,IAA/B,CAAoCF,IAApC,CAAhB;EACA,OAAOC,OAAO,KAAK,IAAZ,GAAmBA,OAAO,CAAC,CAAD,CAA1B,GAAgC,WAAvC;AACD"}
package/dist/_mount.js CHANGED
@@ -27,13 +27,11 @@ class MountHandler extends _local.default {
27
27
  useSudo = false,
28
28
  ...opts
29
29
  } = {}, params) {
30
- var _remote$options;
31
-
32
30
  super(remote, opts);
33
31
  this._execa = useSudo ? sudoExeca : _execa.default;
34
32
  this._keeper = undefined;
35
33
  this._params = { ...params,
36
- options: [params.options, (_remote$options = remote.options) !== null && _remote$options !== void 0 ? _remote$options : params.defaultOptions].filter(_ => _ !== undefined).join(',')
34
+ options: [params.options, remote.options ?? params.defaultOptions].filter(_ => _ !== undefined).join(',')
37
35
  };
38
36
  this._realPath = (0, _path.join)(mountsDir, remote.id || Math.random().toString(36).slice(2));
39
37
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/_mount.js"],"names":["sudoExeca","command","args","opts","MountHandler","LocalHandler","constructor","remote","mountsDir","useSudo","params","_execa","execa","_keeper","undefined","_params","options","defaultOptions","filter","_","join","_realPath","id","Math","random","toString","slice","_forget","keeper","fs","close","ignoreErrors","call","_getRealPath","env","LANG","_sync","realPath","ensureDir","type","device","error","stdio","keeperPath","open","unlink"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AAEA;;;;AAEA,MAAMA,SAAS,GAAG,CAACC,OAAD,EAAUC,IAAV,EAAgBC,IAAhB,KAAyB,oBAAM,MAAN,EAAc,CAACF,OAAD,EAAU,GAAGC,IAAb,CAAd,EAAkCC,IAAlC,CAA3C;;AAEe,MAAMC,YAAN,SAA2BC,cAA3B,CAAwC;AACrDC,EAAAA,WAAW,CAACC,MAAD,EAAS;AAAEC,IAAAA,SAAS,GAAG,gBAAK,iBAAL,EAAe,cAAf,CAAd;AAA8CC,IAAAA,OAAO,GAAG,KAAxD;AAA+D,OAAGN;AAAlE,MAA2E,EAApF,EAAwFO,MAAxF,EAAgG;AAAA;;AACzG,UAAMH,MAAN,EAAcJ,IAAd;AAEA,SAAKQ,MAAL,GAAcF,OAAO,GAAGT,SAAH,GAAeY,cAApC;AACA,SAAKC,OAAL,GAAeC,SAAf;AACA,SAAKC,OAAL,GAAe,EACb,GAAGL,MADU;AAEbM,MAAAA,OAAO,EAAE,CAACN,MAAM,CAACM,OAAR,qBAAiBT,MAAM,CAACS,OAAxB,6DAAmCN,MAAM,CAACO,cAA1C,EAA0DC,MAA1D,CAAiEC,CAAC,IAAIA,CAAC,KAAKL,SAA5E,EAAuFM,IAAvF,CAA4F,GAA5F;AAFI,KAAf;AAIA,SAAKC,SAAL,GAAiB,gBAAKb,SAAL,EAAgBD,MAAM,CAACe,EAAP,IAAaC,IAAI,CAACC,MAAL,GAAcC,QAAd,CAAuB,EAAvB,EAA2BC,KAA3B,CAAiC,CAAjC,CAA7B,CAAjB;AACD;;AAEY,QAAPC,OAAO,GAAG;AACd,UAAMC,MAAM,GAAG,KAAKf,OAApB;;AACA,QAAIe,MAAM,KAAKd,SAAf,EAA0B;AACxB;AACD;;AACD,SAAKD,OAAL,GAAe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F;;AAID,UAAME,UAAU,GAAI,GAAEN,QAAS,YAAWd,IAAI,CAACC,MAAL,GAAcC,QAAd,CAAuB,EAAvB,EAA2BC,KAA3B,CAAiC,CAAjC,CAAoC,EAA9E;AACA,SAAKb,OAAL,GAAe,MAAMgB,iBAAGe,IAAH,CAAQD,UAAR,EAAoB,GAApB,CAArB;;AACAZ,iCAAaC,IAAb,CAAkBH,iBAAGgB,MAAH,CAAUF,UAAV,CAAlB;AACD;;AA5EoD","sourcesContent":["import execa from 'execa'\nimport fs from 'fs-extra'\nimport { ignoreErrors } from 'promise-toolbox'\nimport { join } from 'path'\nimport { tmpdir } from 'os'\n\nimport LocalHandler from './local'\n\nconst sudoExeca = (command, args, opts) => execa('sudo', [command, ...args], opts)\n\nexport default class MountHandler extends LocalHandler {\n constructor(remote, { mountsDir = join(tmpdir(), 'xo-fs-mounts'), useSudo = false, ...opts } = {}, params) {\n super(remote, opts)\n\n this._execa = useSudo ? sudoExeca : execa\n this._keeper = undefined\n this._params = {\n ...params,\n options: [params.options, remote.options ?? params.defaultOptions].filter(_ => _ !== undefined).join(','),\n }\n this._realPath = join(mountsDir, remote.id || Math.random().toString(36).slice(2))\n }\n\n async _forget() {\n const keeper = this._keeper\n if (keeper === undefined) {\n return\n }\n this._keeper = undefined\n await fs.close(keeper)\n\n await ignoreErrors.call(\n this._execa('umount', [this._getRealPath()], {\n env: {\n LANG: 'C',\n },\n })\n )\n }\n\n _getRealPath() {\n return this._realPath\n }\n\n async _sync() {\n // in case of multiple `sync`s, ensure we properly close previous keeper\n {\n const keeper = this._keeper\n if (keeper !== undefined) {\n this._keeper = undefined\n ignoreErrors.call(fs.close(keeper))\n }\n }\n\n const realPath = this._getRealPath()\n\n await fs.ensureDir(realPath)\n\n try {\n const { type, device, options, env } = this._params\n\n // Linux mount is more flexible in which order the mount arguments appear.\n // But FreeBSD requires this order of the arguments.\n await this._execa('mount', ['-o', options, '-t', type, device, realPath], {\n env: {\n LANG: 'C',\n ...env,\n },\n })\n } catch (error) {\n try {\n // the failure may mean it's already mounted, use `findmnt` to check\n // that's the case\n await this._execa('findmnt', [realPath], {\n stdio: 'ignore',\n })\n } catch (_) {\n throw error\n }\n }\n\n // keep an open file on the mount to prevent it from being unmounted if used\n // by another handler/process\n const keeperPath = `${realPath}/.keeper_${Math.random().toString(36).slice(2)}`\n this._keeper = await fs.open(keeperPath, 'w')\n ignoreErrors.call(fs.unlink(keeperPath))\n }\n}\n"],"file":"_mount.js"}
1
+ {"version":3,"file":"_mount.js","names":["sudoExeca","command","args","opts","execa","MountHandler","LocalHandler","constructor","remote","mountsDir","join","tmpdir","useSudo","params","_execa","_keeper","undefined","_params","options","defaultOptions","filter","_","_realPath","id","Math","random","toString","slice","_forget","keeper","fs","close","ignoreErrors","call","_getRealPath","env","LANG","_sync","realPath","ensureDir","type","device","error","stdio","keeperPath","open","unlink"],"sources":["../src/_mount.js"],"sourcesContent":["import execa from 'execa'\nimport fs from 'fs-extra'\nimport { ignoreErrors } from 'promise-toolbox'\nimport { join } from 'path'\nimport { tmpdir } from 'os'\n\nimport LocalHandler from './local'\n\nconst sudoExeca = (command, args, opts) => execa('sudo', [command, ...args], opts)\n\nexport default class MountHandler extends LocalHandler {\n constructor(remote, { mountsDir = join(tmpdir(), 'xo-fs-mounts'), useSudo = false, ...opts } = {}, params) {\n super(remote, opts)\n\n this._execa = useSudo ? sudoExeca : execa\n this._keeper = undefined\n this._params = {\n ...params,\n options: [params.options, remote.options ?? params.defaultOptions].filter(_ => _ !== undefined).join(','),\n }\n this._realPath = join(mountsDir, remote.id || Math.random().toString(36).slice(2))\n }\n\n async _forget() {\n const keeper = this._keeper\n if (keeper === undefined) {\n return\n }\n this._keeper = undefined\n await fs.close(keeper)\n\n await ignoreErrors.call(\n this._execa('umount', [this._getRealPath()], {\n env: {\n LANG: 'C',\n },\n })\n )\n }\n\n _getRealPath() {\n return this._realPath\n }\n\n async _sync() {\n // in case of multiple `sync`s, ensure we properly close previous keeper\n {\n const keeper = this._keeper\n if (keeper !== undefined) {\n this._keeper = undefined\n ignoreErrors.call(fs.close(keeper))\n }\n }\n\n const realPath = this._getRealPath()\n\n await fs.ensureDir(realPath)\n\n try {\n const { type, device, options, env } = this._params\n\n // Linux mount is more flexible in which order the mount arguments appear.\n // But FreeBSD requires this order of the arguments.\n await this._execa('mount', ['-o', options, '-t', type, device, realPath], {\n env: {\n LANG: 'C',\n ...env,\n },\n })\n } catch (error) {\n try {\n // the failure may mean it's already mounted, use `findmnt` to check\n // that's the case\n await this._execa('findmnt', [realPath], {\n stdio: 'ignore',\n })\n } catch (_) {\n throw error\n }\n }\n\n // keep an open file on the mount to prevent it from being unmounted if used\n // by another handler/process\n const keeperPath = `${realPath}/.keeper_${Math.random().toString(36).slice(2)}`\n this._keeper = await fs.open(keeperPath, 'w')\n ignoreErrors.call(fs.unlink(keeperPath))\n }\n}\n"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AAEA;;;;AAEA,MAAMA,SAAS,GAAG,CAACC,OAAD,EAAUC,IAAV,EAAgBC,IAAhB,KAAyB,IAAAC,cAAA,EAAM,MAAN,EAAc,CAACH,OAAD,EAAU,GAAGC,IAAb,CAAd,EAAkCC,IAAlC,CAA3C;;AAEe,MAAME,YAAN,SAA2BC,cAA3B,CAAwC;EACrDC,WAAW,CAACC,MAAD,EAAS;IAAEC,SAAS,GAAG,IAAAC,UAAA,EAAK,IAAAC,UAAA,GAAL,EAAe,cAAf,CAAd;IAA8CC,OAAO,GAAG,KAAxD;IAA+D,GAAGT;EAAlE,IAA2E,EAApF,EAAwFU,MAAxF,EAAgG;IACzG,MAAML,MAAN,EAAcL,IAAd;IAEA,KAAKW,MAAL,GAAcF,OAAO,GAAGZ,SAAH,GAAeI,cAApC;IACA,KAAKW,OAAL,GAAeC,SAAf;IACA,KAAKC,OAAL,GAAe,EACb,GAAGJ,MADU;MAEbK,OAAO,EAAE,CAACL,MAAM,CAACK,OAAR,EAAiBV,MAAM,CAACU,OAAP,I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CAAC,IAAD,EAAOI,OAAP,EAAgB,IAAhB,EAAsBsB,IAAtB,EAA4BC,MAA5B,EAAoCH,QAApC,CAArB,EAAoE;QACxEH,GAAG,EAAE;UACHC,IAAI,EAAE,GADH;UAEH,GAAGD;QAFA;MADmE,CAApE,CAAN;IAMD,CAXD,CAWE,OAAOO,KAAP,EAAc;MACd,IAAI;QAGF,MAAM,KAAK5B,MAAL,CAAY,SAAZ,EAAuB,CAACwB,QAAD,CAAvB,EAAmC;UACvCK,KAAK,EAAE;QADgC,CAAnC,CAAN;MAGD,CAND,CAME,OAAOtB,CAAP,EAAU;QACV,MAAMqB,KAAN;MACD;IACF;;IAID,MAAME,UAAU,GAAI,GAAEN,QAAS,YAAWd,IAAI,CAACC,MAAL,GAAcC,QAAd,CAAuB,EAAvB,EAA2BC,KAA3B,CAAiC,CAAjC,CAAoC,EAA9E;IACA,KAAKZ,OAAL,GAAe,MAAMe,gBAAA,CAAGe,IAAH,CAAQD,UAAR,EAAoB,GAApB,CAArB;;IACAZ,4BAAA,CAAaC,IAAb,CAAkBH,gBAAA,CAAGgB,MAAH,CAAUF,UAAV,CAAlB;EACD;;AA5EoD"}
package/dist/_path.js ADDED
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.normalize = exports.join = exports.dirname = exports.basename = void 0;
7
+ exports.split = split;
8
+
9
+ var _path = _interopRequireDefault(require("path"));
10
+
11
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
+
13
+ const {
14
+ basename,
15
+ dirname,
16
+ join,
17
+ resolve,
18
+ sep
19
+ } = _path.default.posix;
20
+ exports.join = join;
21
+ exports.dirname = dirname;
22
+ exports.basename = basename;
23
+
24
+ const normalize = path => resolve('/', path);
25
+
26
+ exports.normalize = normalize;
27
+
28
+ function split(path) {
29
+ const parts = normalize(path).split(sep);
30
+ parts.shift();
31
+ return parts;
32
+ }
33
+ //# sourceMappingURL=_path.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_path.js","names":["basename","dirname","join","resolve","sep","path","posix","normalize","split","parts","shift"],"sources":["../src/_path.js"],"sourcesContent":["import path from 'path'\n\nconst { basename, dirname, join, resolve, sep } = path.posix\n\nexport { basename, dirname, join }\n\n// normalize the path:\n// - does not contains `.` or `..` (cannot escape root dir)\n// - always starts with `/`\n// - no trailing slash (expect for root)\n// - no duplicate slashes\nexport const normalize = path => resolve('/', path)\n\nexport function split(path) {\n const parts = normalize(path).split(sep)\n\n // remove first (empty) entry\n parts.shift()\n\n return parts\n}\n"],"mappings":";;;;;;;;AAAA;;;;AAEA,MAAM;EAAEA,QAAF;EAAYC,OAAZ;EAAqBC,IAArB;EAA2BC,OAA3B;EAAoCC;AAApC,IAA4CC,aAAA,CAAKC,KAAvD;;;;;AASO,MAAMC,SAAS,GAAGF,IAAI,IAAIF,OAAO,CAAC,GAAD,EAAME,IAAN,CAAjC;;;;AAEA,SAASG,KAAT,CAAeH,IAAf,EAAqB;EAC1B,MAAMI,KAAK,GAAGF,SAAS,CAACF,IAAD,CAAT,CAAgBG,KAAhB,CAAsBJ,GAAtB,CAAd;EAGAK,KAAK,CAACC,KAAN;EAEA,OAAOD,KAAP;AACD"}
package/dist/abstract.js CHANGED
@@ -9,8 +9,6 @@ var _legacy = _interopRequireDefault(require("@xen-orchestra/async-map/legacy"))
9
9
 
10
10
  var _getStream = _interopRequireDefault(require("get-stream"));
11
11
 
12
- var _path = _interopRequireWildcard(require("path"));
13
-
14
12
  var _coalesceCalls = require("@vates/coalesce-calls");
15
13
 
16
14
  var _promiseToolbox = require("promise-toolbox");
@@ -25,24 +23,16 @@ var _crypto = require("crypto");
25
23
 
26
24
  var _decoratorSynchronized = require("decorator-synchronized");
27
25
 
28
- var _normalizePath = _interopRequireDefault(require("./_normalizePath"));
26
+ var _path = require("./_path");
29
27
 
30
28
  var _checksum = require("./checksum");
31
29
 
32
30
  var _dec, _dec2, _class;
33
31
 
34
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
35
-
36
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
37
-
38
32
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
39
33
 
40
34
  function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { var desc = {}; Object.keys(descriptor).forEach(function (key) { desc[key] = descriptor[key]; }); desc.enumerable = !!desc.enumerable; desc.configurable = !!desc.configurable; if ('value' in desc || desc.initializer) { desc.writable = true; } desc = decorators.slice().reverse().reduce(function (desc, decorator) { return decorator(target, property, desc) || desc; }, desc); if (context && desc.initializer !== void 0) { desc.value = desc.initializer ? desc.initializer.call(context) : void 0; desc.initializer = undefined; } if (desc.initializer === void 0) { Object.defineProperty(target, property, desc); desc = null; } return desc; }
41
35
 
42
- const {
43
- dirname
44
- } = _path.default.posix;
45
-
46
36
  const checksumFile = file => file + '.checksum';
47
37
 
48
38
  const computeRate = (hrtime, size) => {
@@ -89,15 +79,13 @@ class PrefixWrapper {
89
79
  }
90
80
 
91
81
  _resolve(path) {
92
- return this._prefix + (0, _normalizePath.default)(path);
82
+ return this._prefix + (0, _path.normalize)(path);
93
83
  }
94
84
 
95
85
  }
96
86
 
97
87
  let RemoteHandlerAbstract = (_dec = (0, _decoratorSynchronized.synchronized)(), _dec2 = (0, _decoratorSynchronized.synchronized)(), (_class = class RemoteHandlerAbstract {
98
88
  constructor(remote, options = {}) {
99
- var _options$maxParallelO;
100
-
101
89
  if (remote.url === 'test://') {
102
90
  this._remote = remote;
103
91
  } else {
@@ -115,7 +103,7 @@ let RemoteHandlerAbstract = (_dec = (0, _decoratorSynchronized.synchronized)(),
115
103
  highWaterMark: this._highWaterMark,
116
104
  timeout: this._timeout = DEFAULT_TIMEOUT
117
105
  } = options);
118
- const sharedLimit = (0, _limitConcurrencyDecorator.limitConcurrency)((_options$maxParallelO = options.maxParallelOperations) !== null && _options$maxParallelO !== void 0 ? _options$maxParallelO : DEFAULT_MAX_PARALLEL_OPERATIONS);
106
+ const sharedLimit = (0, _limitConcurrencyDecorator.limitConcurrency)(options.maxParallelOperations ?? DEFAULT_MAX_PARALLEL_OPERATIONS);
119
107
  this.closeFile = sharedLimit(this.closeFile);
120
108
  this.copy = sharedLimit(this.copy);
121
109
  this.getInfo = sharedLimit(this.getInfo);
@@ -141,7 +129,7 @@ let RemoteHandlerAbstract = (_dec = (0, _decoratorSynchronized.synchronized)(),
141
129
  }
142
130
 
143
131
  addPrefix(prefix) {
144
- prefix = (0, _normalizePath.default)(prefix);
132
+ prefix = (0, _path.normalize)(prefix);
145
133
  return prefix === '/' ? this : new PrefixWrapper(this, prefix);
146
134
  }
147
135
 
@@ -155,7 +143,7 @@ let RemoteHandlerAbstract = (_dec = (0, _decoratorSynchronized.synchronized)(),
155
143
  ...options
156
144
  } = {}) {
157
145
  if (typeof file === 'string') {
158
- file = (0, _normalizePath.default)(file);
146
+ file = (0, _path.normalize)(file);
159
147
  }
160
148
 
161
149
  const path = typeof file === 'string' ? file : file.path;
@@ -191,7 +179,7 @@ let RemoteHandlerAbstract = (_dec = (0, _decoratorSynchronized.synchronized)(),
191
179
  ...options
192
180
  } = {}) {
193
181
  if (typeof file === 'string') {
194
- file = (0, _normalizePath.default)(file);
182
+ file = (0, _path.normalize)(file);
195
183
  }
196
184
 
197
185
  const path = typeof file === 'string' ? file : file.path;
@@ -239,7 +227,7 @@ let RemoteHandlerAbstract = (_dec = (0, _decoratorSynchronized.synchronized)(),
239
227
  dirMode,
240
228
  validator
241
229
  } = {}) {
242
- path = (0, _normalizePath.default)(path);
230
+ path = (0, _path.normalize)(path);
243
231
  let checksumStream;
244
232
 
245
233
  if (checksum) {
@@ -270,7 +258,7 @@ let RemoteHandlerAbstract = (_dec = (0, _decoratorSynchronized.synchronized)(),
270
258
  }
271
259
 
272
260
  async getSize(file) {
273
- return _promiseToolbox.timeout.call(this._getSize(typeof file === 'string' ? (0, _normalizePath.default)(file) : file), this._timeout);
261
+ return _promiseToolbox.timeout.call(this._getSize(typeof file === 'string' ? (0, _path.normalize)(file) : file), this._timeout);
274
262
  }
275
263
 
276
264
  async list(dir, {
@@ -279,8 +267,8 @@ let RemoteHandlerAbstract = (_dec = (0, _decoratorSynchronized.synchronized)(),
279
267
  prependDir = false
280
268
  } = {}) {
281
269
  try {
282
- const virtualDir = (0, _normalizePath.default)(dir);
283
- dir = (0, _normalizePath.default)(dir);
270
+ const virtualDir = (0, _path.normalize)(dir);
271
+ dir = (0, _path.normalize)(dir);
284
272
  let entries = await _promiseToolbox.timeout.call(this._list(dir), this._timeout);
285
273
 
286
274
  if (filter !== undefined) {
@@ -304,7 +292,7 @@ let RemoteHandlerAbstract = (_dec = (0, _decoratorSynchronized.synchronized)(),
304
292
  }
305
293
 
306
294
  async lock(path) {
307
- path = (0, _normalizePath.default)(path);
295
+ path = (0, _path.normalize)(path);
308
296
  return {
309
297
  dispose: await this._lock(path)
310
298
  };
@@ -313,7 +301,7 @@ let RemoteHandlerAbstract = (_dec = (0, _decoratorSynchronized.synchronized)(),
313
301
  async mkdir(dir, {
314
302
  mode
315
303
  } = {}) {
316
- await this.__mkdir((0, _normalizePath.default)(dir), {
304
+ await this.__mkdir((0, _path.normalize)(dir), {
317
305
  mode
318
306
  });
319
307
  }
@@ -321,7 +309,7 @@ let RemoteHandlerAbstract = (_dec = (0, _decoratorSynchronized.synchronized)(),
321
309
  async mktree(dir, {
322
310
  mode
323
311
  } = {}) {
324
- await this._mktree((0, _normalizePath.default)(dir), {
312
+ await this._mktree((0, _path.normalize)(dir), {
325
313
  mode
326
314
  });
327
315
  }
@@ -334,20 +322,20 @@ let RemoteHandlerAbstract = (_dec = (0, _decoratorSynchronized.synchronized)(),
334
322
  dirMode,
335
323
  flags = 'wx'
336
324
  } = {}) {
337
- await this._outputFile((0, _normalizePath.default)(file), data, {
325
+ await this._outputFile((0, _path.normalize)(file), data, {
338
326
  dirMode,
339
327
  flags
340
328
  });
341
329
  }
342
330
 
343
331
  async read(file, buffer, position) {
344
- return this._read(typeof file === 'string' ? (0, _normalizePath.default)(file) : file, buffer, position);
332
+ return this._read(typeof file === 'string' ? (0, _path.normalize)(file) : file, buffer, position);
345
333
  }
346
334
 
347
335
  async readFile(file, {
348
336
  flags = 'r'
349
337
  } = {}) {
350
- return this._readFile((0, _normalizePath.default)(file), {
338
+ return this._readFile((0, _path.normalize)(file), {
351
339
  flags
352
340
  });
353
341
  }
@@ -355,8 +343,8 @@ let RemoteHandlerAbstract = (_dec = (0, _decoratorSynchronized.synchronized)(),
355
343
  async rename(oldPath, newPath, {
356
344
  checksum = false
357
345
  } = {}) {
358
- oldPath = (0, _normalizePath.default)(oldPath);
359
- newPath = (0, _normalizePath.default)(newPath);
346
+ oldPath = (0, _path.normalize)(oldPath);
347
+ newPath = (0, _path.normalize)(newPath);
360
348
 
361
349
  let p = _promiseToolbox.timeout.call(this._rename(oldPath, newPath), this._timeout);
362
350
 
@@ -370,8 +358,8 @@ let RemoteHandlerAbstract = (_dec = (0, _decoratorSynchronized.synchronized)(),
370
358
  async copy(oldPath, newPath, {
371
359
  checksum = false
372
360
  } = {}) {
373
- oldPath = (0, _normalizePath.default)(oldPath);
374
- newPath = (0, _normalizePath.default)(newPath);
361
+ oldPath = (0, _path.normalize)(oldPath);
362
+ newPath = (0, _path.normalize)(newPath);
375
363
 
376
364
  let p = _promiseToolbox.timeout.call(this._copy(oldPath, newPath), this._timeout);
377
365
 
@@ -383,11 +371,11 @@ let RemoteHandlerAbstract = (_dec = (0, _decoratorSynchronized.synchronized)(),
383
371
  }
384
372
 
385
373
  async rmdir(dir) {
386
- await _promiseToolbox.timeout.call(this._rmdir((0, _normalizePath.default)(dir)).catch(ignoreEnoent), this._timeout);
374
+ await _promiseToolbox.timeout.call(this._rmdir((0, _path.normalize)(dir)).catch(ignoreEnoent), this._timeout);
387
375
  }
388
376
 
389
377
  async rmtree(dir) {
390
- await this._rmtree((0, _normalizePath.default)(dir));
378
+ await this._rmtree((0, _path.normalize)(dir));
391
379
  }
392
380
 
393
381
  async sync() {
@@ -396,7 +384,7 @@ let RemoteHandlerAbstract = (_dec = (0, _decoratorSynchronized.synchronized)(),
396
384
 
397
385
  async test() {
398
386
  const SIZE = 1024 * 1024 * 10;
399
- const testFileName = (0, _normalizePath.default)(`${Date.now()}.test`);
387
+ const testFileName = (0, _path.normalize)(`${Date.now()}.test`);
400
388
  const data = await (0, _promiseToolbox.fromCallback)(_crypto.randomBytes, SIZE);
401
389
  let step = 'write';
402
390
 
@@ -441,7 +429,7 @@ let RemoteHandlerAbstract = (_dec = (0, _decoratorSynchronized.synchronized)(),
441
429
  async unlink(file, {
442
430
  checksum = true
443
431
  } = {}) {
444
- file = (0, _normalizePath.default)(file);
432
+ file = (0, _path.normalize)(file);
445
433
 
446
434
  if (checksum) {
447
435
  _promiseToolbox.ignoreErrors.call(this._unlink(checksumFile(file)));
@@ -451,13 +439,13 @@ let RemoteHandlerAbstract = (_dec = (0, _decoratorSynchronized.synchronized)(),
451
439
  }
452
440
 
453
441
  async write(file, buffer, position) {
454
- await this._write(typeof file === 'string' ? (0, _normalizePath.default)(file) : file, buffer, position);
442
+ await this._write(typeof file === 'string' ? (0, _path.normalize)(file) : file, buffer, position);
455
443
  }
456
444
 
457
445
  async writeFile(file, data, {
458
446
  flags = 'wx'
459
447
  } = {}) {
460
- await this._writeFile((0, _normalizePath.default)(file), data, {
448
+ await this._writeFile((0, _path.normalize)(file), data, {
461
449
  flags
462
450
  });
463
451
  }
@@ -483,7 +471,7 @@ let RemoteHandlerAbstract = (_dec = (0, _decoratorSynchronized.synchronized)(),
483
471
  }
484
472
 
485
473
  async __openFile(path, flags) {
486
- path = (0, _normalizePath.default)(path);
474
+ path = (0, _path.normalize)(path);
487
475
  return {
488
476
  fd: await _promiseToolbox.timeout.call(this._openFile(path, flags), this._timeout),
489
477
  path
@@ -508,7 +496,7 @@ let RemoteHandlerAbstract = (_dec = (0, _decoratorSynchronized.synchronized)(),
508
496
  }
509
497
  }
510
498
 
511
- await this._mktree(dirname(file), {
499
+ await this._mktree((0, _path.dirname)(file), {
512
500
  mode: dirMode
513
501
  });
514
502
  return this._createOutputStream(file, options);
@@ -557,7 +545,7 @@ let RemoteHandlerAbstract = (_dec = (0, _decoratorSynchronized.synchronized)(),
557
545
  }
558
546
  }
559
547
 
560
- await this._mktree(dirname(dir), {
548
+ await this._mktree((0, _path.dirname)(dir), {
561
549
  mode
562
550
  });
563
551
  return this._mktree(dir, {
@@ -583,7 +571,7 @@ let RemoteHandlerAbstract = (_dec = (0, _decoratorSynchronized.synchronized)(),
583
571
  }
584
572
  }
585
573
 
586
- await this._mktree(dirname(file), {
574
+ await this._mktree((0, _path.dirname)(file), {
587
575
  mode: dirMode
588
576
  });
589
577
  return this._outputFile(file, data, {
@@ -595,7 +583,7 @@ let RemoteHandlerAbstract = (_dec = (0, _decoratorSynchronized.synchronized)(),
595
583
  dirMode,
596
584
  validator
597
585
  }) {
598
- const tmpPath = `${dirname(path)}/.${(0, _path.basename)(path)}`;
586
+ const tmpPath = `${(0, _path.dirname)(path)}/.${(0, _path.basename)(path)}`;
599
587
  const output = await this.createOutputStream(tmpPath, {
600
588
  dirMode
601
589
  });
@@ -647,7 +635,7 @@ let RemoteHandlerAbstract = (_dec = (0, _decoratorSynchronized.synchronized)(),
647
635
 
648
636
  const files = await this._list(dir);
649
637
  await (0, _legacy.default)(files, file => this._unlink(`${dir}/${file}`).catch(error => {
650
- if (error.code === 'EISDIR') {
638
+ if (error.code === 'EISDIR' || error.code === 'EPERM') {
651
639
  return this._rmtree(`${dir}/${file}`);
652
640
  }
653
641