1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-07-13 00:10:37 +02:00

Fixed OneDrive sync issue

This commit is contained in:
Laurent Cozic
2017-06-23 23:19:59 +01:00
parent 45ac9daebe
commit e89447dd85
4 changed files with 34 additions and 6 deletions

View File

@ -40,7 +40,7 @@ class FileApiDriverOneDrive {
}; };
} }
async stat(path) { async statRaw_(path) {
let item = null; let item = null;
try { try {
item = await this.api_.execJson('GET', this.makePath_(path), this.itemFilter_()); item = await this.api_.execJson('GET', this.makePath_(path), this.itemFilter_());
@ -48,6 +48,12 @@ class FileApiDriverOneDrive {
if (error.error.code == 'itemNotFound') return null; if (error.error.code == 'itemNotFound') return null;
throw error; throw error;
} }
return item;
}
async stat(path) {
let item = await this.statRaw_(path);
if (!item) return null;
return this.makeItem_(item); return this.makeItem_(item);
} }
@ -57,7 +63,8 @@ class FileApiDriverOneDrive {
lastModifiedDateTime: moment.unix(timestamp / 1000).utc().format('YYYY-MM-DDTHH:mm:ss.SSS') + 'Z', lastModifiedDateTime: moment.unix(timestamp / 1000).utc().format('YYYY-MM-DDTHH:mm:ss.SSS') + 'Z',
} }
}; };
await this.api_.exec('PATCH', this.makePath_(path), null, body); let item = await this.api_.execJson('PATCH', this.makePath_(path), null, body);
return this.makeItem_(item);
} }
async list(path) { async list(path) {
@ -101,12 +108,20 @@ class FileApiDriverOneDrive {
} }
async move(oldPath, newPath) { async move(oldPath, newPath) {
let previousItem = await this.statRaw_(oldPath);
let newDir = dirname(newPath); let newDir = dirname(newPath);
let newName = basename(newPath); let newName = basename(newPath);
// We don't want the modification date to change when we move the file so retrieve it
// now set it in the PATCH operation.
let item = await this.api_.execJson('PATCH', this.makePath_(oldPath), this.itemFilter_(), { let item = await this.api_.execJson('PATCH', this.makePath_(oldPath), this.itemFilter_(), {
name: newName, name: newName,
parentReference: { path: newDir }, parentReference: { path: newDir },
fileSystemInfo: {
lastModifiedDateTime: previousItem.fileSystemInfo.lastModifiedDateTime,
},
}); });
return this.makeItem_(item); return this.makeItem_(item);

View File

@ -52,8 +52,20 @@ class Logger {
console[fn](line + object); console[fn](line + object);
} }
} else if (t.type == 'file') { } else if (t.type == 'file') {
if (typeof object === 'object') object = JSON.stringify(object); let serializedObject = '';
fs.appendFile(t.path, line + object + "\n", (error) => {
if (typeof object === 'object') {
if (object instanceof Error) {
serializedObject = object.toString();
if (object.stack) serializedObject += "\n" + object.stack;
} else {
serializedObject = JSON.stringify(object);
}
} else {
serializedObject = object;
}
fs.appendFile(t.path, line + serializedObject + "\n", (error) => {
if (error) throw error; if (error) throw error;
}); });
} }

View File

@ -86,7 +86,7 @@ class Folder extends BaseItem {
} }
static loadNoteByField(folderId, field, value) { static loadNoteByField(folderId, field, value) {
return this.modelSelectAll('SELECT * FROM notes WHERE is_conflict = 0 AND `parent_id` = ? AND `' + field + '` = ?', [folderId, value]); return this.modelSelectOne('SELECT * FROM notes WHERE is_conflict = 0 AND `parent_id` = ? AND `' + field + '` = ?', [folderId, value]);
} }
static async all(includeNotes = false) { static async all(includeNotes = false) {

View File

@ -93,6 +93,7 @@ class Synchronizer {
// Make the operation atomic by doing the work on a copy of the file // Make the operation atomic by doing the work on a copy of the file
// and then copying it back to the original location. // and then copying it back to the original location.
let tempPath = this.syncDirName_ + '/' + path; let tempPath = this.syncDirName_ + '/' + path;
await this.api().put(tempPath, content); await this.api().put(tempPath, content);
await this.api().setTimestamp(tempPath, local.updated_time); await this.api().setTimestamp(tempPath, local.updated_time);
await this.api().move(tempPath, path); await this.api().move(tempPath, path);