Bug 1676803 - [remote] Hardening discards of registered FileIO streams. r=remote-protocol-reviewers,jdescottes

In some situations the FileIO stream's underlying file might not
exist anymore. Discarding the stream should not fail.

Depends on D112004

Differential Revision: https://phabricator.services.mozilla.com/D113379
This commit is contained in:
Henrik Skupin 2021-04-26 19:46:09 +00:00
parent 8bcc373610
commit 460f0ed59f

View File

@ -47,14 +47,16 @@ class StreamRegistry {
async _discard(stream) {
if (stream instanceof OS.File) {
const fileInfo = await stream.stat();
stream.close();
let fileInfo;
// Also remove the temporary file
try {
fileInfo = await stream.stat();
stream.close();
await OS.File.remove(fileInfo.path, { ignoreAbsent: true });
} catch (e) {
console.error(`Failed to remove ${fileInfo.path}: ${e.message}`);
console.error(`Failed to remove ${fileInfo?.path}: ${e.message}`);
}
}
}