1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-12-05 22:57:29 +02:00

Fixed race condition when testing with memory driver and fixed encoding issue

This commit is contained in:
Laurent Cozic
2018-02-15 17:12:09 +00:00
parent 81bc975193
commit 3551c26e28
4 changed files with 22 additions and 24 deletions

View File

@@ -18,7 +18,7 @@ class FileApiDriverMemory {
}
decodeContent_(content) {
return Buffer.from(content, 'base64').toString('ascii');
return Buffer.from(content, 'base64').toString('utf-8');
}
itemIndexByPath(path) {
@@ -49,14 +49,13 @@ class FileApiDriverMemory {
return Promise.resolve(item ? Object.assign({}, item) : null);
}
setTimestamp(path, timestampMs) {
async setTimestamp(path, timestampMs) {
let item = this.itemByPath(path);
if (!item) return Promise.reject(new Error('File not found: ' + path));
item.updated_time = timestampMs;
return Promise.resolve();
}
list(path, options) {
async list(path, options) {
let output = [];
for (let i = 0; i < this.items_.length; i++) {
@@ -95,11 +94,10 @@ class FileApiDriverMemory {
return output;
}
mkdir(path) {
async mkdir(path) {
let index = this.itemIndexByPath(path);
if (index >= 0) return Promise.resolve();
if (index >= 0) return;
this.items_.push(this.newItem(path, true));
return Promise.resolve();
}
async put(path, content, options = null) {
@@ -116,10 +114,9 @@ class FileApiDriverMemory {
this.items_[index].content = this.encodeContent_(content);
this.items_[index].updated_time = time.unix();
}
return Promise.resolve();
}
delete(path) {
async delete(path) {
let index = this.itemIndexByPath(path);
if (index >= 0) {
let item = Object.assign({}, this.items_[index]);
@@ -128,20 +125,17 @@ class FileApiDriverMemory {
this.deletedItems_.push(item);
this.items_.splice(index, 1);
}
return Promise.resolve();
}
move(oldPath, newPath) {
async move(oldPath, newPath) {
let sourceItem = this.itemByPath(oldPath);
if (!sourceItem) return Promise.reject(new Error('Path not found: ' + oldPath));
this.delete(newPath); // Overwrite if newPath already exists
sourceItem.path = newPath;
return Promise.resolve();
}
format() {
async format() {
this.items_ = [];
return Promise.resolve();
}
async delta(path, options = null) {
@@ -159,9 +153,8 @@ class FileApiDriverMemory {
return output;
}
clearRoot() {
async clearRoot() {
this.items_ = [];
return Promise.resolve();
}
}