@xen-orchestra/fs 3.3.4 → 4.0.0
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/_encryptor.js.map +1 -1
- package/dist/_mount.js +19 -16
- package/dist/_mount.js.map +1 -1
- package/dist/abstract.js +45 -46
- package/dist/abstract.js.map +1 -1
- package/dist/checksum.js.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/local.js +36 -34
- package/dist/local.js.map +1 -1
- package/dist/path.js.map +1 -1
- package/dist/s3.js +57 -54
- package/dist/s3.js.map +1 -1
- package/package.json +8 -4
package/dist/_encryptor.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_encryptor.js","names":["pipeline","require","readChunk","crypto","DEFAULT_ENCRYPTION_ALGORITHM","exports","UNENCRYPTED_ALGORITHM","isLegacyEncryptionAlgorithm","algorithm","getEncryptor","key","undefined","id","ivLength","encryptData","buffer","encryptStream","stream","decryptData","decryptStream","info","getCipherInfo","keyLength","length","error","Error","getCiphers","code","mode","authTagLength","includes","input","source","iv","randomBytes","cipher","createCipheriv","Buffer","from","data","update","final","getAuthTag","encryptedStream","createDecipheriv","authTag","alloc","slice","fullData","concat","fullDataLength","setAuthTag","encrypted","decipher","decrypted","_getEncryptor"],"sources":["../src/_encryptor.js"],"sourcesContent":["const { pipeline } = require('node:stream')\nconst { readChunk } = require('@vates/read-chunk')\nconst crypto = require('crypto')\n\nexport const DEFAULT_ENCRYPTION_ALGORITHM = 'aes-256-gcm'\nexport const UNENCRYPTED_ALGORITHM = 'none'\n\nexport function isLegacyEncryptionAlgorithm(algorithm) {\n return algorithm !== UNENCRYPTED_ALGORITHM && algorithm !== DEFAULT_ENCRYPTION_ALGORITHM\n}\n\nfunction getEncryptor(algorithm = DEFAULT_ENCRYPTION_ALGORITHM, key) {\n if (key === undefined) {\n return {\n id: 'NULL_ENCRYPTOR',\n algorithm: 'none',\n key: 'none',\n ivLength: 0,\n encryptData: buffer => buffer,\n encryptStream: stream => stream,\n decryptData: buffer => buffer,\n decryptStream: stream => stream,\n }\n }\n const info = crypto.getCipherInfo(algorithm, { keyLength: key.length })\n if (info === undefined) {\n const error = new Error(\n `Either the algorithm ${algorithm} is not available, or the key length ${\n key.length\n } is incorrect. Supported algorithm are ${crypto.getCiphers()}`\n )\n error.code = 'BAD_ALGORITHM'\n throw error\n }\n const { ivLength, mode } = info\n const authTagLength = ['gcm', 'ccm', 'ocb'].includes(mode) ? 16 : 0\n\n function encryptStream(input) {\n return pipeline(\n input,\n async function* (source) {\n const iv = crypto.randomBytes(ivLength)\n const cipher = crypto.createCipheriv(algorithm, Buffer.from(key), iv)\n yield iv\n for await (const data of source) {\n yield cipher.update(data)\n }\n yield cipher.final()\n // must write the auth tag at the end of the encryption stream\n if (authTagLength > 0) {\n yield cipher.getAuthTag()\n }\n },\n () => {}\n )\n }\n\n function decryptStream(encryptedStream) {\n return pipeline(\n encryptedStream,\n async function* (source) {\n /**\n * WARNING\n *\n * the crypted size has an initializtion vector + eventually an auth tag + a padding at the end\n * whe can't predict the decrypted size from the start of the encrypted size\n * thus, we can't set decrypted.length reliably\n *\n */\n\n const iv = await readChunk(source, ivLength)\n const cipher = crypto.createDecipheriv(algorithm, Buffer.from(key), iv)\n let authTag = Buffer.alloc(0)\n for await (const data of source) {\n if (data.length >= authTagLength) {\n // fast path, no buffer concat\n yield cipher.update(authTag)\n authTag = data.slice(data.length - authTagLength)\n yield cipher.update(data.slice(0, data.length - authTagLength))\n } else {\n // slower since there is a concat\n const fullData = Buffer.concat([authTag, data])\n const fullDataLength = fullData.length\n if (fullDataLength > authTagLength) {\n authTag = fullData.slice(fullDataLength - authTagLength)\n yield cipher.update(fullData.slice(0, fullDataLength - authTagLength))\n } else {\n authTag = fullData\n }\n }\n }\n if (authTagLength > 0) {\n cipher.setAuthTag(authTag)\n }\n yield cipher.final()\n },\n () => {}\n )\n }\n\n function encryptData(buffer) {\n const iv = crypto.randomBytes(ivLength)\n const cipher = crypto.createCipheriv(algorithm, Buffer.from(key), iv)\n const encrypted = cipher.update(buffer)\n return Buffer.concat([iv, encrypted, cipher.final(), authTagLength > 0 ? cipher.getAuthTag() : Buffer.alloc(0)])\n }\n\n function decryptData(buffer) {\n const iv = buffer.slice(0, ivLength)\n const decipher = crypto.createDecipheriv(algorithm, Buffer.from(key), iv)\n let encrypted\n if (authTagLength > 0) {\n const authTag = buffer.slice(buffer.length - authTagLength)\n decipher.setAuthTag(authTag)\n encrypted = buffer.slice(ivLength, buffer.length - authTagLength)\n } else {\n encrypted = buffer.slice(ivLength)\n }\n const decrypted = decipher.update(encrypted)\n return Buffer.concat([decrypted, decipher.final()])\n }\n\n return {\n id: algorithm,\n algorithm,\n key,\n ivLength,\n encryptData,\n encryptStream,\n decryptData,\n decryptStream,\n }\n}\n\nexports._getEncryptor = getEncryptor\n"],"mappings":";;;;;;;AAAA,MAAM;EAAEA;AAAS,CAAC,GAAGC,OAAO,CAAC,aAAa,CAAC;AAC3C,MAAM;EAAEC;AAAU,CAAC,GAAGD,OAAO,CAAC,mBAAmB,CAAC;AAClD,MAAME,MAAM,GAAGF,OAAO,CAAC,QAAQ,CAAC;AAEzB,MAAMG,4BAA4B,GAAG,aAAa;AAAAC,OAAA,CAAAD,4BAAA,GAAAA,4BAAA;AAClD,MAAME,qBAAqB,GAAG,MAAM;AAAAD,OAAA,CAAAC,qBAAA,GAAAA,qBAAA;AAEpC,SAASC,2BAA2BA,CAACC,SAAS,EAAE;EACrD,OAAOA,SAAS,KAAKF,qBAAqB,IAAIE,SAAS,KAAKJ,4BAA4B;AAC1F;AAEA,SAASK,YAAYA,CAACD,SAAS,GAAGJ,4BAA4B,EAAEM,GAAG,EAAE;EACnE,IAAIA,GAAG,KAAKC,SAAS,EAAE;IACrB,OAAO;MACLC,EAAE,EAAE,gBAAgB;MACpBJ,SAAS,EAAE,MAAM;MACjBE,GAAG,EAAE,MAAM;MACXG,QAAQ,EAAE,CAAC;MACXC,WAAW,EAAEC,MAAM,IAAIA,MAAM;MAC7BC,aAAa,EAAEC,MAAM,IAAIA,MAAM;MAC/BC,WAAW,EAAEH,MAAM,IAAIA,MAAM;MAC7BI,aAAa,EAAEF,MAAM,IAAIA;IAC3B,CAAC;EACH;EACA,MAAMG,IAAI,GAAGjB,MAAM,CAACkB,aAAa,CAACb,SAAS,EAAE;IAAEc,SAAS,EAAEZ,GAAG,CAACa;EAAO,CAAC,CAAC;EACvE,IAAIH,IAAI,KAAKT,SAAS,EAAE;IACtB,MAAMa,KAAK,GAAG,IAAIC,KAAK,CACpB,wBAAuBjB,SAAU,wCAChCE,GAAG,CAACa,MACL,0CAAyCpB,MAAM,CAACuB,UAAU,
|
|
1
|
+
{"version":3,"file":"_encryptor.js","names":["pipeline","require","readChunk","crypto","DEFAULT_ENCRYPTION_ALGORITHM","exports","UNENCRYPTED_ALGORITHM","isLegacyEncryptionAlgorithm","algorithm","getEncryptor","key","undefined","id","ivLength","encryptData","buffer","encryptStream","stream","decryptData","decryptStream","info","getCipherInfo","keyLength","length","error","Error","getCiphers","code","mode","authTagLength","includes","input","source","iv","randomBytes","cipher","createCipheriv","Buffer","from","data","update","final","getAuthTag","encryptedStream","createDecipheriv","authTag","alloc","slice","fullData","concat","fullDataLength","setAuthTag","encrypted","decipher","decrypted","_getEncryptor"],"sources":["../src/_encryptor.js"],"sourcesContent":["const { pipeline } = require('node:stream')\nconst { readChunk } = require('@vates/read-chunk')\nconst crypto = require('crypto')\n\nexport const DEFAULT_ENCRYPTION_ALGORITHM = 'aes-256-gcm'\nexport const UNENCRYPTED_ALGORITHM = 'none'\n\nexport function isLegacyEncryptionAlgorithm(algorithm) {\n return algorithm !== UNENCRYPTED_ALGORITHM && algorithm !== DEFAULT_ENCRYPTION_ALGORITHM\n}\n\nfunction getEncryptor(algorithm = DEFAULT_ENCRYPTION_ALGORITHM, key) {\n if (key === undefined) {\n return {\n id: 'NULL_ENCRYPTOR',\n algorithm: 'none',\n key: 'none',\n ivLength: 0,\n encryptData: buffer => buffer,\n encryptStream: stream => stream,\n decryptData: buffer => buffer,\n decryptStream: stream => stream,\n }\n }\n const info = crypto.getCipherInfo(algorithm, { keyLength: key.length })\n if (info === undefined) {\n const error = new Error(\n `Either the algorithm ${algorithm} is not available, or the key length ${\n key.length\n } is incorrect. Supported algorithm are ${crypto.getCiphers()}`\n )\n error.code = 'BAD_ALGORITHM'\n throw error\n }\n const { ivLength, mode } = info\n const authTagLength = ['gcm', 'ccm', 'ocb'].includes(mode) ? 16 : 0\n\n function encryptStream(input) {\n return pipeline(\n input,\n async function* (source) {\n const iv = crypto.randomBytes(ivLength)\n const cipher = crypto.createCipheriv(algorithm, Buffer.from(key), iv)\n yield iv\n for await (const data of source) {\n yield cipher.update(data)\n }\n yield cipher.final()\n // must write the auth tag at the end of the encryption stream\n if (authTagLength > 0) {\n yield cipher.getAuthTag()\n }\n },\n () => {}\n )\n }\n\n function decryptStream(encryptedStream) {\n return pipeline(\n encryptedStream,\n async function* (source) {\n /**\n * WARNING\n *\n * the crypted size has an initializtion vector + eventually an auth tag + a padding at the end\n * whe can't predict the decrypted size from the start of the encrypted size\n * thus, we can't set decrypted.length reliably\n *\n */\n\n const iv = await readChunk(source, ivLength)\n const cipher = crypto.createDecipheriv(algorithm, Buffer.from(key), iv)\n let authTag = Buffer.alloc(0)\n for await (const data of source) {\n if (data.length >= authTagLength) {\n // fast path, no buffer concat\n yield cipher.update(authTag)\n authTag = data.slice(data.length - authTagLength)\n yield cipher.update(data.slice(0, data.length - authTagLength))\n } else {\n // slower since there is a concat\n const fullData = Buffer.concat([authTag, data])\n const fullDataLength = fullData.length\n if (fullDataLength > authTagLength) {\n authTag = fullData.slice(fullDataLength - authTagLength)\n yield cipher.update(fullData.slice(0, fullDataLength - authTagLength))\n } else {\n authTag = fullData\n }\n }\n }\n if (authTagLength > 0) {\n cipher.setAuthTag(authTag)\n }\n yield cipher.final()\n },\n () => {}\n )\n }\n\n function encryptData(buffer) {\n const iv = crypto.randomBytes(ivLength)\n const cipher = crypto.createCipheriv(algorithm, Buffer.from(key), iv)\n const encrypted = cipher.update(buffer)\n return Buffer.concat([iv, encrypted, cipher.final(), authTagLength > 0 ? cipher.getAuthTag() : Buffer.alloc(0)])\n }\n\n function decryptData(buffer) {\n const iv = buffer.slice(0, ivLength)\n const decipher = crypto.createDecipheriv(algorithm, Buffer.from(key), iv)\n let encrypted\n if (authTagLength > 0) {\n const authTag = buffer.slice(buffer.length - authTagLength)\n decipher.setAuthTag(authTag)\n encrypted = buffer.slice(ivLength, buffer.length - authTagLength)\n } else {\n encrypted = buffer.slice(ivLength)\n }\n const decrypted = decipher.update(encrypted)\n return Buffer.concat([decrypted, decipher.final()])\n }\n\n return {\n id: algorithm,\n algorithm,\n key,\n ivLength,\n encryptData,\n encryptStream,\n decryptData,\n decryptStream,\n }\n}\n\nexports._getEncryptor = getEncryptor\n"],"mappings":";;;;;;;AAAA,MAAM;EAAEA;AAAS,CAAC,GAAGC,OAAO,CAAC,aAAa,CAAC;AAC3C,MAAM;EAAEC;AAAU,CAAC,GAAGD,OAAO,CAAC,mBAAmB,CAAC;AAClD,MAAME,MAAM,GAAGF,OAAO,CAAC,QAAQ,CAAC;AAEzB,MAAMG,4BAA4B,GAAG,aAAa;AAAAC,OAAA,CAAAD,4BAAA,GAAAA,4BAAA;AAClD,MAAME,qBAAqB,GAAG,MAAM;AAAAD,OAAA,CAAAC,qBAAA,GAAAA,qBAAA;AAEpC,SAASC,2BAA2BA,CAACC,SAAS,EAAE;EACrD,OAAOA,SAAS,KAAKF,qBAAqB,IAAIE,SAAS,KAAKJ,4BAA4B;AAC1F;AAEA,SAASK,YAAYA,CAACD,SAAS,GAAGJ,4BAA4B,EAAEM,GAAG,EAAE;EACnE,IAAIA,GAAG,KAAKC,SAAS,EAAE;IACrB,OAAO;MACLC,EAAE,EAAE,gBAAgB;MACpBJ,SAAS,EAAE,MAAM;MACjBE,GAAG,EAAE,MAAM;MACXG,QAAQ,EAAE,CAAC;MAC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AAEE,MAAM,CAACQ,MAAM,GAAGM,aAAa,CAAC;IACnE,CAAC,MAAM;MACLuB,SAAS,GAAGrC,MAAM,CAACgC,KAAK,CAAClC,QAAQ,CAAC;IACpC;IACA,MAAMyC,SAAS,GAAGD,QAAQ,CAACb,MAAM,CAACY,SAAS,CAAC;IAC5C,OAAOf,MAAM,CAACY,MAAM,CAAC,CAACK,SAAS,EAAED,QAAQ,CAACZ,KAAK,CAAC,CAAC,CAAC,CAAC;EACrD;EAEA,OAAO;IACL7B,EAAE,EAAEJ,SAAS;IACbA,SAAS;IACTE,GAAG;IACHG,QAAQ;IACRC,WAAW;IACXE,aAAa;IACbE,WAAW;IACXC;EACF,CAAC;AACH;AAEAd,OAAO,CAACkD,aAAa,GAAG9C,YAAY"}
|
package/dist/_mount.js
CHANGED
|
@@ -13,45 +13,48 @@ var _local = _interopRequireDefault(require("./local"));
|
|
|
13
13
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
14
|
const sudoExeca = (command, args, opts) => (0, _execa.default)('sudo', [command, ...args], opts);
|
|
15
15
|
class MountHandler extends _local.default {
|
|
16
|
+
#execa;
|
|
17
|
+
#keeper;
|
|
18
|
+
#params;
|
|
19
|
+
#realPath;
|
|
16
20
|
constructor(remote, {
|
|
17
21
|
mountsDir = (0, _path.join)((0, _os.tmpdir)(), 'xo-fs-mounts'),
|
|
18
22
|
useSudo = false,
|
|
19
23
|
...opts
|
|
20
24
|
} = {}, params) {
|
|
21
25
|
super(remote, opts);
|
|
22
|
-
this
|
|
23
|
-
this
|
|
24
|
-
this._params = {
|
|
26
|
+
this.#execa = useSudo ? sudoExeca : _execa.default;
|
|
27
|
+
this.#params = {
|
|
25
28
|
...params,
|
|
26
29
|
options: [params.options, remote.options ?? params.defaultOptions].filter(_ => _ !== undefined).join(',')
|
|
27
30
|
};
|
|
28
|
-
this
|
|
31
|
+
this.#realPath = (0, _path.join)(mountsDir, remote.id || Math.random().toString(36).slice(2));
|
|
29
32
|
}
|
|
30
33
|
async _forget() {
|
|
31
|
-
const keeper = this
|
|
34
|
+
const keeper = this.#keeper;
|
|
32
35
|
if (keeper === undefined) {
|
|
33
36
|
return;
|
|
34
37
|
}
|
|
35
|
-
this
|
|
38
|
+
this.#keeper = undefined;
|
|
36
39
|
await _fsExtra.default.close(keeper);
|
|
37
|
-
await _promiseToolbox.ignoreErrors.call(this
|
|
40
|
+
await _promiseToolbox.ignoreErrors.call(this.#execa('umount', [this.getRealPath()], {
|
|
38
41
|
env: {
|
|
39
42
|
LANG: 'C'
|
|
40
43
|
}
|
|
41
44
|
}));
|
|
42
45
|
}
|
|
43
|
-
|
|
44
|
-
return this
|
|
46
|
+
getRealPath() {
|
|
47
|
+
return this.#realPath;
|
|
45
48
|
}
|
|
46
49
|
async _sync() {
|
|
47
50
|
{
|
|
48
|
-
const keeper = this
|
|
51
|
+
const keeper = this.#keeper;
|
|
49
52
|
if (keeper !== undefined) {
|
|
50
|
-
this
|
|
53
|
+
this.#keeper = undefined;
|
|
51
54
|
_promiseToolbox.ignoreErrors.call(_fsExtra.default.close(keeper));
|
|
52
55
|
}
|
|
53
56
|
}
|
|
54
|
-
const realPath = this.
|
|
57
|
+
const realPath = this.getRealPath();
|
|
55
58
|
await _fsExtra.default.ensureDir(realPath);
|
|
56
59
|
try {
|
|
57
60
|
const {
|
|
@@ -59,8 +62,8 @@ class MountHandler extends _local.default {
|
|
|
59
62
|
device,
|
|
60
63
|
options,
|
|
61
64
|
env
|
|
62
|
-
} = this
|
|
63
|
-
await this
|
|
65
|
+
} = this.#params;
|
|
66
|
+
await this.#execa('mount', ['-o', options, '-t', type, device, realPath], {
|
|
64
67
|
env: {
|
|
65
68
|
LANG: 'C',
|
|
66
69
|
...env
|
|
@@ -68,7 +71,7 @@ class MountHandler extends _local.default {
|
|
|
68
71
|
});
|
|
69
72
|
} catch (error) {
|
|
70
73
|
try {
|
|
71
|
-
await this
|
|
74
|
+
await this.#execa('findmnt', [realPath], {
|
|
72
75
|
stdio: 'ignore'
|
|
73
76
|
});
|
|
74
77
|
} catch (_) {
|
|
@@ -76,7 +79,7 @@ class MountHandler extends _local.default {
|
|
|
76
79
|
}
|
|
77
80
|
}
|
|
78
81
|
const keeperPath = `${realPath}/.keeper_${Math.random().toString(36).slice(2)}`;
|
|
79
|
-
this
|
|
82
|
+
this.#keeper = await _fsExtra.default.open(keeperPath, 'w');
|
|
80
83
|
_promiseToolbox.ignoreErrors.call(_fsExtra.default.unlink(keeperPath));
|
|
81
84
|
}
|
|
82
85
|
}
|
package/dist/_mount.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_mount.js","names":["_execa","_interopRequireDefault","require","_fsExtra","_promiseToolbox","_path","_os","_local","obj","__esModule","default","sudoExeca","command","args","opts","execa","MountHandler","LocalHandler","
|
|
1
|
+
{"version":3,"file":"_mount.js","names":["_execa","_interopRequireDefault","require","_fsExtra","_promiseToolbox","_path","_os","_local","obj","__esModule","default","sudoExeca","command","args","opts","execa","MountHandler","LocalHandler","keeper","params","realPath","constructor","remote","mountsDir","join","tmpdir","useSudo","options","defaultOptions","filter","_","undefined","id","Math","random","toString","slice","_forget","fs","close","ignoreErrors","call","getRealPath","env","LANG","_sync","ensureDir","type","device","error","stdio","keeperPath","open","unlink","exports"],"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 #execa\n #keeper\n #params\n #realPath\n\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.#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,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,QAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,eAAA,GAAAF,OAAA;AACA,IAAAG,KAAA,GAAAH,OAAA;AACA,IAAAI,GAAA,GAAAJ,OAAA;AAEA,IAAAK,MAAA,GAAAN,sBAAA,CAAAC,OAAA;AAAkC,SAAAD,uBAAAO,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAElC,MAAMG,SAAS,GAAGA,CAACC,O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AU,GAAI,GAAE/B,QAAS,YAAWa,IAAI,CAACC,MAAM,CAAC,CAAC,CAACC,QAAQ,CAAC,EAAE,CAAC,CAACC,KAAK,CAAC,CAAC,CAAE,EAAC;IAC/E,IAAI,CAAC,CAAClB,MAAM,GAAG,MAAMoB,gBAAE,CAACc,IAAI,CAACD,UAAU,EAAE,GAAG,CAAC;IAC7CX,4BAAY,CAACC,IAAI,CAACH,gBAAE,CAACe,MAAM,CAACF,UAAU,CAAC,CAAC;EAC1C;AACF;AAACG,OAAA,CAAA5C,OAAA,GAAAM,YAAA"}
|
package/dist/abstract.js
CHANGED
|
@@ -41,8 +41,9 @@ const ignoreEnoent = error => {
|
|
|
41
41
|
};
|
|
42
42
|
const noop = Function.prototype;
|
|
43
43
|
class PrefixWrapper {
|
|
44
|
+
#prefix;
|
|
44
45
|
constructor(handler, prefix) {
|
|
45
|
-
this
|
|
46
|
+
this.#prefix = prefix;
|
|
46
47
|
this._handler = handler;
|
|
47
48
|
}
|
|
48
49
|
get type() {
|
|
@@ -51,7 +52,7 @@ class PrefixWrapper {
|
|
|
51
52
|
async list(dir, opts) {
|
|
52
53
|
const entries = await this._handler.list(this._resolve(dir), opts);
|
|
53
54
|
if (opts != null && opts.prependDir) {
|
|
54
|
-
const n = this.
|
|
55
|
+
const n = this.#prefix.length;
|
|
55
56
|
entries.forEach((entry, i, entries) => {
|
|
56
57
|
entries[i] = entry.slice(n);
|
|
57
58
|
});
|
|
@@ -62,16 +63,16 @@ class PrefixWrapper {
|
|
|
62
63
|
return this._handler.rename(this._resolve(oldPath), this._resolve(newPath));
|
|
63
64
|
}
|
|
64
65
|
_resolve(path) {
|
|
65
|
-
return this
|
|
66
|
+
return this.#prefix + (0, _path.normalize)(path);
|
|
66
67
|
}
|
|
67
68
|
}
|
|
68
69
|
let RemoteHandlerAbstract = (_dec = (0, _decoratorSynchronized.synchronized)(), _dec2 = (0, _decoratorSynchronized.synchronized)(), (_class = class RemoteHandlerAbstract {
|
|
69
|
-
#
|
|
70
|
-
get
|
|
71
|
-
if (this.#
|
|
70
|
+
#rawEncryptor;
|
|
71
|
+
get #encryptor() {
|
|
72
|
+
if (this.#rawEncryptor === undefined) {
|
|
72
73
|
throw new Error(`Can't access to encryptor before remote synchronization`);
|
|
73
74
|
}
|
|
74
|
-
return this.#
|
|
75
|
+
return this.#rawEncryptor;
|
|
75
76
|
}
|
|
76
77
|
constructor(remote, options = {}) {
|
|
77
78
|
if (remote.url === 'test://') {
|
|
@@ -117,9 +118,6 @@ let RemoteHandlerAbstract = (_dec = (0, _decoratorSynchronized.synchronized)(),
|
|
|
117
118
|
prefix = (0, _path.normalize)(prefix);
|
|
118
119
|
return prefix === '/' ? this : new PrefixWrapper(this, prefix);
|
|
119
120
|
}
|
|
120
|
-
async closeFile(fd) {
|
|
121
|
-
await this.__closeFile(fd);
|
|
122
|
-
}
|
|
123
121
|
async createReadStream(file, {
|
|
124
122
|
checksum = false,
|
|
125
123
|
ignoreMissingChecksum = false,
|
|
@@ -154,7 +152,7 @@ let RemoteHandlerAbstract = (_dec = (0, _decoratorSynchronized.synchronized)(),
|
|
|
154
152
|
}
|
|
155
153
|
}
|
|
156
154
|
if (this.isEncrypted) {
|
|
157
|
-
stream = this.
|
|
155
|
+
stream = this.#encryptor.decryptStream(stream);
|
|
158
156
|
} else {
|
|
159
157
|
if (stream.length === undefined && options.end === undefined && options.start === undefined) {
|
|
160
158
|
try {
|
|
@@ -171,7 +169,7 @@ let RemoteHandlerAbstract = (_dec = (0, _decoratorSynchronized.synchronized)(),
|
|
|
171
169
|
} = {}) {
|
|
172
170
|
path = (0, _path.normalize)(path);
|
|
173
171
|
let checksumStream;
|
|
174
|
-
input = this.
|
|
172
|
+
input = this.#encryptor.encryptStream(input);
|
|
175
173
|
if (checksum) {
|
|
176
174
|
checksumStream = (0, _checksum.createChecksumStream)();
|
|
177
175
|
(0, _stream.pipeline)(input, checksumStream, noop);
|
|
@@ -197,9 +195,9 @@ let RemoteHandlerAbstract = (_dec = (0, _decoratorSynchronized.synchronized)(),
|
|
|
197
195
|
async getSize(file) {
|
|
198
196
|
_assert.default.strictEqual(this.isEncrypted, false, `Can't compute size of an encrypted file ${file}`);
|
|
199
197
|
const size = await _promiseToolbox.timeout.call(this._getSize(typeof file === 'string' ? (0, _path.normalize)(file) : file), this._timeout);
|
|
200
|
-
return size - this.
|
|
198
|
+
return size - this.#encryptor.ivLength;
|
|
201
199
|
}
|
|
202
|
-
async
|
|
200
|
+
async __list(dir, {
|
|
203
201
|
filter,
|
|
204
202
|
ignoreMissing = false,
|
|
205
203
|
prependDir = false
|
|
@@ -230,13 +228,6 @@ let RemoteHandlerAbstract = (_dec = (0, _decoratorSynchronized.synchronized)(),
|
|
|
230
228
|
dispose: await this._lock(path)
|
|
231
229
|
};
|
|
232
230
|
}
|
|
233
|
-
async mkdir(dir, {
|
|
234
|
-
mode
|
|
235
|
-
} = {}) {
|
|
236
|
-
await this.__mkdir((0, _path.normalize)(dir), {
|
|
237
|
-
mode
|
|
238
|
-
});
|
|
239
|
-
}
|
|
240
231
|
async mktree(dir, {
|
|
241
232
|
mode
|
|
242
233
|
} = {}) {
|
|
@@ -244,14 +235,11 @@ let RemoteHandlerAbstract = (_dec = (0, _decoratorSynchronized.synchronized)(),
|
|
|
244
235
|
mode
|
|
245
236
|
});
|
|
246
237
|
}
|
|
247
|
-
openFile(path, flags) {
|
|
248
|
-
return this.__openFile(path, flags);
|
|
249
|
-
}
|
|
250
238
|
async outputFile(file, data, {
|
|
251
239
|
dirMode,
|
|
252
240
|
flags = 'wx'
|
|
253
241
|
} = {}) {
|
|
254
|
-
const encryptedData = this.
|
|
242
|
+
const encryptedData = this.#encryptor.encryptData(data);
|
|
255
243
|
await this._outputFile((0, _path.normalize)(file), encryptedData, {
|
|
256
244
|
dirMode,
|
|
257
245
|
flags
|
|
@@ -261,13 +249,13 @@ let RemoteHandlerAbstract = (_dec = (0, _decoratorSynchronized.synchronized)(),
|
|
|
261
249
|
_assert.default.strictEqual(this.isEncrypted, false, `Can't read part of an encrypted file ${file}`);
|
|
262
250
|
return this._read(typeof file === 'string' ? (0, _path.normalize)(file) : file, buffer, position);
|
|
263
251
|
}
|
|
264
|
-
async
|
|
252
|
+
async __readFile(file, {
|
|
265
253
|
flags = 'r'
|
|
266
254
|
} = {}) {
|
|
267
255
|
const data = await this._readFile((0, _path.normalize)(file), {
|
|
268
256
|
flags
|
|
269
257
|
});
|
|
270
|
-
return this.
|
|
258
|
+
return this.#encryptor.decryptData(data);
|
|
271
259
|
}
|
|
272
260
|
async #rename(oldPath, newPath, {
|
|
273
261
|
checksum
|
|
@@ -288,14 +276,14 @@ let RemoteHandlerAbstract = (_dec = (0, _decoratorSynchronized.synchronized)(),
|
|
|
288
276
|
throw error;
|
|
289
277
|
}
|
|
290
278
|
}
|
|
291
|
-
|
|
279
|
+
__rename(oldPath, newPath, {
|
|
292
280
|
checksum = false
|
|
293
281
|
} = {}) {
|
|
294
282
|
return this.#rename((0, _path.normalize)(oldPath), (0, _path.normalize)(newPath), {
|
|
295
283
|
checksum
|
|
296
284
|
});
|
|
297
285
|
}
|
|
298
|
-
async
|
|
286
|
+
async __copy(oldPath, newPath, {
|
|
299
287
|
checksum = false
|
|
300
288
|
} = {}) {
|
|
301
289
|
oldPath = (0, _path.normalize)(oldPath);
|
|
@@ -315,30 +303,30 @@ let RemoteHandlerAbstract = (_dec = (0, _decoratorSynchronized.synchronized)(),
|
|
|
315
303
|
async sync() {
|
|
316
304
|
await this._sync();
|
|
317
305
|
try {
|
|
318
|
-
await this
|
|
306
|
+
await this.#checkMetadata();
|
|
319
307
|
} catch (error) {
|
|
320
308
|
await this._forget();
|
|
321
309
|
throw error;
|
|
322
310
|
}
|
|
323
311
|
}
|
|
324
|
-
async
|
|
325
|
-
const list = await this.
|
|
312
|
+
async #canWriteMetadata() {
|
|
313
|
+
const list = await this.__list('/', {
|
|
326
314
|
filter: e => !e.startsWith('.') && e !== ENCRYPTION_DESC_FILENAME && e !== ENCRYPTION_METADATA_FILENAME
|
|
327
315
|
});
|
|
328
316
|
return list.length === 0;
|
|
329
317
|
}
|
|
330
|
-
async
|
|
318
|
+
async #createMetadata() {
|
|
331
319
|
const encryptionAlgorithm = this._remote.encryptionKey === undefined ? 'none' : _encryptor.DEFAULT_ENCRYPTION_ALGORITHM;
|
|
332
|
-
this.#
|
|
320
|
+
this.#rawEncryptor = (0, _encryptor._getEncryptor)(encryptionAlgorithm, this._remote.encryptionKey);
|
|
333
321
|
await Promise.all([this._writeFile((0, _path.normalize)(ENCRYPTION_DESC_FILENAME), JSON.stringify({
|
|
334
322
|
algorithm: encryptionAlgorithm
|
|
335
323
|
}), {
|
|
336
324
|
flags: 'w'
|
|
337
|
-
}), this.
|
|
325
|
+
}), this.__writeFile(ENCRYPTION_METADATA_FILENAME, `{"random":"${(0, _crypto.randomUUID)()}"}`, {
|
|
338
326
|
flags: 'w'
|
|
339
327
|
})]);
|
|
340
328
|
}
|
|
341
|
-
async
|
|
329
|
+
async #checkMetadata() {
|
|
342
330
|
let encryptionAlgorithm = 'none';
|
|
343
331
|
let data;
|
|
344
332
|
try {
|
|
@@ -352,14 +340,14 @@ let RemoteHandlerAbstract = (_dec = (0, _decoratorSynchronized.synchronized)(),
|
|
|
352
340
|
encryptionAlgorithm = this._remote.encryptionKey === undefined ? 'none' : _encryptor.DEFAULT_ENCRYPTION_ALGORITHM;
|
|
353
341
|
}
|
|
354
342
|
try {
|
|
355
|
-
this.#
|
|
356
|
-
const data = await this.
|
|
343
|
+
this.#rawEncryptor = (0, _encryptor._getEncryptor)(encryptionAlgorithm, this._remote.encryptionKey);
|
|
344
|
+
const data = await this.__readFile(ENCRYPTION_METADATA_FILENAME, 'utf-8');
|
|
357
345
|
JSON.parse(data);
|
|
358
346
|
} catch (error) {
|
|
359
347
|
if (encryptionAlgorithm !== 'none') {
|
|
360
|
-
if (await this
|
|
348
|
+
if (await this.#canWriteMetadata()) {
|
|
361
349
|
info('will update metadata of this remote');
|
|
362
|
-
return this
|
|
350
|
+
return this.#createMetadata();
|
|
363
351
|
} else {
|
|
364
352
|
warn(`The encryptionKey settings of this remote does not match the key used to create it. You won't be able to read any data from this remote`, {
|
|
365
353
|
error
|
|
@@ -411,7 +399,7 @@ let RemoteHandlerAbstract = (_dec = (0, _decoratorSynchronized.synchronized)(),
|
|
|
411
399
|
async truncate(file, len) {
|
|
412
400
|
await this._truncate(file, len);
|
|
413
401
|
}
|
|
414
|
-
async
|
|
402
|
+
async __unlink(file, {
|
|
415
403
|
checksum = true
|
|
416
404
|
} = {}) {
|
|
417
405
|
file = (0, _path.normalize)(file);
|
|
@@ -424,10 +412,10 @@ let RemoteHandlerAbstract = (_dec = (0, _decoratorSynchronized.synchronized)(),
|
|
|
424
412
|
_assert.default.strictEqual(this.isEncrypted, false, `Can't write part of a file with encryption ${file}`);
|
|
425
413
|
await this._write(typeof file === 'string' ? (0, _path.normalize)(file) : file, buffer, position);
|
|
426
414
|
}
|
|
427
|
-
async
|
|
415
|
+
async __writeFile(file, data, {
|
|
428
416
|
flags = 'wx'
|
|
429
417
|
} = {}) {
|
|
430
|
-
const encryptedData = this.
|
|
418
|
+
const encryptedData = this.#encryptor.encryptData(data);
|
|
431
419
|
await this._writeFile((0, _path.normalize)(file), encryptedData, {
|
|
432
420
|
flags
|
|
433
421
|
});
|
|
@@ -438,6 +426,7 @@ let RemoteHandlerAbstract = (_dec = (0, _decoratorSynchronized.synchronized)(),
|
|
|
438
426
|
async __mkdir(dir, {
|
|
439
427
|
mode
|
|
440
428
|
} = {}) {
|
|
429
|
+
dir = (0, _path.normalize)(dir);
|
|
441
430
|
try {
|
|
442
431
|
await this._mkdir(dir, {
|
|
443
432
|
mode
|
|
@@ -559,9 +548,9 @@ let RemoteHandlerAbstract = (_dec = (0, _decoratorSynchronized.synchronized)(),
|
|
|
559
548
|
if (validator !== undefined) {
|
|
560
549
|
await validator.call(this, tmpPath);
|
|
561
550
|
}
|
|
562
|
-
await this.
|
|
551
|
+
await this.__rename(tmpPath, path);
|
|
563
552
|
} catch (error) {
|
|
564
|
-
await this.
|
|
553
|
+
await this.__unlink(tmpPath);
|
|
565
554
|
throw error;
|
|
566
555
|
}
|
|
567
556
|
}
|
|
@@ -624,10 +613,20 @@ let RemoteHandlerAbstract = (_dec = (0, _decoratorSynchronized.synchronized)(),
|
|
|
624
613
|
throw new Error('Not implemented');
|
|
625
614
|
}
|
|
626
615
|
get isEncrypted() {
|
|
627
|
-
return this.
|
|
616
|
+
return this.#encryptor.id !== 'NULL_ENCRYPTOR';
|
|
628
617
|
}
|
|
629
618
|
}, (_applyDecoratedDescriptor(_class.prototype, "forget", [_dec], Object.getOwnPropertyDescriptor(_class.prototype, "forget"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "sync", [_dec2], Object.getOwnPropertyDescriptor(_class.prototype, "sync"), _class.prototype)), _class));
|
|
630
619
|
exports.default = RemoteHandlerAbstract;
|
|
620
|
+
{
|
|
621
|
+
const proto = RemoteHandlerAbstract.prototype;
|
|
622
|
+
for (const method of Object.getOwnPropertyNames(proto)) {
|
|
623
|
+
if (method.startsWith('__')) {
|
|
624
|
+
const publicName = method.slice(2);
|
|
625
|
+
(0, _assert.default)(!Object.hasOwn(proto, publicName));
|
|
626
|
+
Object.defineProperty(proto, publicName, Object.getOwnPropertyDescriptor(proto, method));
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
}
|
|
631
630
|
function createPrefixWrapperMethods() {
|
|
632
631
|
const pPw = PrefixWrapper.prototype;
|
|
633
632
|
const pRha = RemoteHandlerAbstract.prototype;
|