Skip to content
This repository has been archived by the owner on Sep 19, 2023. It is now read-only.

Commit

Permalink
Merge pull request #32 from matrix-org/michaelkaye/fix_removed_files
Browse files Browse the repository at this point in the history
Make a copy of unencrypted files before scanning
  • Loading branch information
michaelkaye committed Nov 28, 2018
2 parents c4cfb0d + 4784b64 commit 1f258fe
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/reporting.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,10 @@ async function generateReport(console, httpUrl, matrixFile, filePath, tempDir, s
return reportCache[reportHash];
}

// By default, the file is considered decrypted
let decryptedFilePath = filePath;
// Always make a decryptedFile on disk
let decryptedFilePath = path.join(tempDir, 'unsafeDownloadedDecryptedFile');

if (matrixFile && matrixFile.key) {
decryptedFilePath = path.join(tempDir, 'unsafeDownloadedDecryptedFile');
console.info(`Decrypting ${filePath}, writing to ${decryptedFilePath}`);

try {
Expand All @@ -271,6 +270,13 @@ async function generateReport(console, httpUrl, matrixFile, filePath, tempDir, s
console.error(err);
throw new ClientError(400, 'Failed to decrypt file', 'MCS_MEDIA_FAILED_TO_DECRYPT');
}
} else {
try {
fs.copyFileSync(filePath, decryptedFilePath);
} catch (err) {
console.error(err);
throw new ClientError(400, 'Failed to copy file for decryption', 'MCS_MEDIA_FAILED_TO_DECRYPT');
}
}

const cmd = script + ' ' + decryptedFilePath;
Expand Down

0 comments on commit 1f258fe

Please sign in to comment.