bugfix in the hash library
This commit is contained in:
@@ -276,26 +276,26 @@ export class HashIndexManager {
|
|||||||
if (!filePath || !fileSize || !mtime || !hashs) {
|
if (!filePath || !fileSize || !mtime || !hashs) {
|
||||||
throw new Error('Invalid parameters');
|
throw new Error('Invalid parameters');
|
||||||
}
|
}
|
||||||
for (const hash of this.targetHash) {
|
// Check that at least one target hash is provided
|
||||||
if (!hashs[hash]) {
|
const providedHashes = this.targetHash.filter(hash => hashs[hash]);
|
||||||
throw new Error(`Missing hash ${hash}`);
|
if (providedHashes.length === 0) {
|
||||||
}
|
throw new Error('At least one target hash must be provided');
|
||||||
}
|
}
|
||||||
const size = fileSize + "";
|
const size = fileSize + "";
|
||||||
const baseName = path.basename(filePath);
|
const baseName = path.basename(filePath);
|
||||||
const cacheKey = `${baseName}-${size}-${mtime}`;
|
const cacheKey = `${baseName}-${size}-${mtime}`;
|
||||||
let indexLine = this.cache.get(cacheKey);
|
let indexLine = this.cache.get(cacheKey);
|
||||||
if (!indexLine) {
|
if (!indexLine) {
|
||||||
//filter only the hashes we need
|
// Filter only the hashes we need (and are provided)
|
||||||
let filteredHash = {};
|
let filteredHash = {};
|
||||||
for (const hash of this.targetHash) {
|
for (const hash of providedHashes) {
|
||||||
filteredHash[hash] = hashs[hash];
|
filteredHash[hash] = hashs[hash];
|
||||||
}
|
}
|
||||||
const data = {path: baseName, size: size, mtime: mtime, ...filteredHash};
|
const data = {path: baseName, size: size, mtime: mtime, ...filteredHash};
|
||||||
this.cache.set(cacheKey, data);
|
this.cache.set(cacheKey, data);
|
||||||
} else {
|
} else {
|
||||||
//update the cache with the latest data
|
// Update the cache with the provided hashes (don't overwrite with undefined)
|
||||||
for (const hash of this.targetHash) {
|
for (const hash of providedHashes) {
|
||||||
indexLine[hash] = hashs[hash];
|
indexLine[hash] = hashs[hash];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user