You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-11-26 22:41:17 +02:00
Co-authored-by: Laurent Cozic <laurent22@users.noreply.github.com>
This commit is contained in:
@@ -9,6 +9,7 @@ import * as tar from 'tar-stream';
|
|||||||
import { resolve } from 'path';
|
import { resolve } from 'path';
|
||||||
import { Buffer } from 'buffer';
|
import { Buffer } from 'buffer';
|
||||||
import Logger from '@joplin/utils/Logger';
|
import Logger from '@joplin/utils/Logger';
|
||||||
|
import JoplinError from '@joplin/lib/JoplinError';
|
||||||
|
|
||||||
const logger = Logger.create('fs-driver-rn');
|
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') {
|
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);
|
const encoding = normalizeEncoding(rawEncoding);
|
||||||
|
|
||||||
if (handle.offset + length > handle.stat.size) {
|
if (handle.offset + length > handle.stat.size) {
|
||||||
|
|||||||
@@ -167,6 +167,18 @@ const testReadFileChunkUtf8 = async (tempDir: string) => {
|
|||||||
|
|
||||||
await fsDriver.close(filePath);
|
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) => {
|
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 : '',
|
masterKeyId: share && share.master_key_id ? share.master_key_id : '',
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} 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;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user