mirror of
https://github.com/laurent22/joplin.git
synced 2025-01-11 18:24:43 +02:00
Co-authored-by: Laurent Cozic <laurent22@users.noreply.github.com>
This commit is contained in:
parent
ca6762c891
commit
e6e9f92e01
@ -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) {
|
||||
|
@ -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) => {
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user