1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-01-11 18:24:43 +02:00

Mobile: Fixes #9123: Fix encryption when a resource doesn't have an associated file (#9222)

Co-authored-by: Laurent Cozic <laurent22@users.noreply.github.com>
This commit is contained in:
Henry Heino 2023-11-10 06:22:26 -08:00 committed by GitHub
parent ca6762c891
commit e6e9f92e01
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 1 deletions

View File

@ -9,6 +9,7 @@ import * as tar from 'tar-stream';
import { resolve } from 'path';
import { Buffer } from 'buffer';
import Logger from '@joplin/utils/Logger';
import JoplinError from '@joplin/lib/JoplinError';
const logger = Logger.create('fs-driver-rn');
@ -285,6 +286,10 @@ export default class FsDriverRN extends FsDriverBase {
}
public async readFileChunk(handle: any, length: number, rawEncoding = 'base64') {
if (!handle?.stat) {
throw new JoplinError('File does not exist (reading file chunk).', 'ENOENT');
}
const encoding = normalizeEncoding(rawEncoding);
if (handle.offset + length > handle.stat.size) {

View File

@ -167,6 +167,18 @@ const testReadFileChunkUtf8 = async (tempDir: string) => {
await fsDriver.close(filePath);
}
// Should throw when the file doesn't exist
let readData = undefined;
try {
const handle = await fsDriver.open(`${filePath}.noexist`, 'r');
readData = await fsDriver.readFileChunk(handle, 1, 'utf8');
} catch (error) {
await expectToBe(error.code, 'ENOENT');
}
// Should not have read any data
await expectToBe(readData, undefined);
};
const testTarCreate = async (tempDir: string) => {

View File

@ -224,7 +224,11 @@ export default class Resource extends BaseItem {
masterKeyId: share && share.master_key_id ? share.master_key_id : '',
});
} catch (error) {
if (error.code === 'ENOENT') throw new JoplinError(`File not found:${error.toString()}`, 'fileNotFound');
if (error.code === 'ENOENT') {
throw new JoplinError(
`Trying to encrypt resource but only metadata is present: ${error.toString()}`, 'fileNotFound',
);
}
throw error;
}