EncFS enable retrieving and updating self (null paths)

This commit is contained in:
Jiang Yio 2022-10-01 07:39:45 -04:00
parent 7c0e1bfbcf
commit 3821cef116

View File

@ -116,13 +116,13 @@ export function TplFS(client, parent, desc) {
this.update = async (path, data) => {
if((typeof path === 'string') || (path instanceof String)) path = path.split('/');
if(path.length > 0) return await (await this.open(path)).update([], data);
if((path) && (path.length > 0)) return await (await this.open(path)).update([], data);
else return await this.raw_update(data);
};
this.cat = async (path=[]) => {
this.cat = async (path) => {
if((typeof path === 'string') || (path instanceof String)) path = path.split('/');
if(path.length > 0) return await (await this.open(path)).raw_cat();
if((path) && (path.length > 0)) return await (await this.open(path)).raw_cat();
else return await this.raw_cat();
};
@ -279,13 +279,17 @@ EncFS.fromPassword = async function(fs, password) {
return String.fromCharCode.apply(null, new Uint8Array(res));
}
async function path_encrypt(data) {
if((data) && (data.constructor === Array)) return await Promise.all(data.map(x => path_component_encrypt(x)));
else return (await Promise.all(data.split('/').map(x => path_component_encrypt(x)))).join('/');
if(data) {
if(data.constructor === Array) return await Promise.all(data.map(x => path_component_encrypt(x)));
else return (await Promise.all(data.split('/').map(x => path_component_encrypt(x)))).join('/');
} else return data;
}
async function path_decrypt(data) {
if((data) && (data.constructor === Array)) return await Promise.all(data.map(x => path_component_decrypt(x)));
else if(data.startsWith('/')) return '/' + await path_decrypt(data.replace(/^\/+/g, ''));
else return (await Promise.all(data.split('/').map(x => path_component_decrypt(x)))).join('/');
if(data) {
if(data.constructor === Array) return await Promise.all(data.map(x => path_component_decrypt(x)));
else if(data.startsWith('/')) return '/' + await path_decrypt(data.replace(/^\/+/g, ''));
else return (await Promise.all(data.split('/').map(x => path_component_decrypt(x)))).join('/');
} else return data;
}
return new EncFS((await fs.mkdir('ZZZE ' + uint8array_to_b64(new Uint8Array(await digest('SHA-1', password))))).chroot(), data_encrypt, data_decrypt, path_encrypt, path_decrypt);
};