make cache optional
This commit is contained in:
parent
336b86c3fd
commit
14a2ba2831
3 changed files with 11 additions and 9 deletions
|
@ -69,7 +69,7 @@ console.log(response);
|
|||
|
||||
- `plain` - the directory containing the original, unencrypted files
|
||||
- `crypt` - the directory containing the encrypted file store to update
|
||||
- `cache` - the path of the file to maintain various hash information
|
||||
- `cache` (optional) - the path of the file to maintain various hash information
|
||||
- `filter` (optional) - a function that is passed a path (the portion after `plain`) and returns whether the given file should be included in the encrypted file store
|
||||
- `passphrase` (optional) - if passed, also delete unused `-data` files and reuse symmetric encryption parameters on renamed input files so the resultant encrypted files are also effectively renamed
|
||||
|
||||
|
@ -94,7 +94,7 @@ console.log(response);
|
|||
|
||||
- `crypt` - the directory containing the encrypted file store to decrypt
|
||||
- `plain` - the destination directory for the decrypted files
|
||||
- `cache` - the path of the file to maintain various hash information
|
||||
- `cache` (optional) - the path of the file to maintain various hash information
|
||||
- `filter` (optional) - a function that is passed a path (the portion after `plain`) and returns whether the given file should be decrypted from the encrypted file store, including whether it should be deleted if it does not exist in the store
|
||||
- `passphrase` - the passphrase for the private key
|
||||
|
||||
|
|
14
crypt.js
14
crypt.js
|
@ -66,11 +66,11 @@ function get_info(crypt_dir, passphrase) {
|
|||
}
|
||||
|
||||
async function get_plain_index(plain_dir, hash_algorithm, filter, cache_path) {
|
||||
let cache;
|
||||
try {
|
||||
cache = deserialize(fs.readFileSync(cache_path));
|
||||
} catch {
|
||||
cache = new Map();
|
||||
let cache = new Map();
|
||||
if (cache_path) {
|
||||
try {
|
||||
cache = deserialize(fs.readFileSync(cache_path));
|
||||
} catch {}
|
||||
}
|
||||
const plain_index = new Map();
|
||||
const pending = [plain_dir];
|
||||
|
@ -107,7 +107,9 @@ async function get_plain_index(plain_dir, hash_algorithm, filter, cache_path) {
|
|||
}
|
||||
}
|
||||
await stream_queue.done();
|
||||
fs.writeFileSync(cache_path, serialize(cache));
|
||||
if (cache_path) {
|
||||
fs.writeFileSync(cache_path, serialize(cache));
|
||||
}
|
||||
return plain_index;
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ const get_config = async () => {
|
|||
if (
|
||||
typeof config.plain !== 'string' ||
|
||||
(config.filter && typeof config.filter !== 'function') ||
|
||||
typeof config.cache !== 'string'
|
||||
(config.cache && typeof config.cache !== 'string')
|
||||
) {
|
||||
console.log(`Invalid configuration shape in ${process.cwd()}/${file}`);
|
||||
process.exit(1);
|
||||
|
|
Loading…
Add table
Reference in a new issue