Skip to content

Commit

Permalink
All: Fixes #632: Handle restricted_content error in Dropbox
Browse files Browse the repository at this point in the history
  • Loading branch information
laurent22 committed Jun 18, 2018
1 parent 44f9b35 commit a8b58aa
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 19 deletions.
2 changes: 2 additions & 0 deletions ReactNativeClient/lib/file-api-driver-dropbox.js
Expand Up @@ -133,6 +133,8 @@ class FileApiDriverDropbox {
} catch (error) {
if (this.hasErrorCode_(error, 'not_found')) {
return null;
} else if (this.hasErrorCode_(error, 'restricted_content')) {
throw new JoplinError('Cannot download because content is restricted by Dropbox', 'rejectedByTarget');
} else {
throw error;
}
Expand Down
69 changes: 50 additions & 19 deletions ReactNativeClient/lib/synchronizer.js
Expand Up @@ -266,7 +266,17 @@ class Synchronizer {
// could be done using the file timestamp and the potentially unnecessary content loading could be skipped.
// OneDrive does not appear to have accurate timestamps as lastModifiedDateTime would occasionally be
// a few seconds ahead of what it was set with setTimestamp()
remoteContent = await this.api().get(path);
try {
remoteContent = await this.api().get(path);
} catch (error) {
if (error.code === 'rejectedByTarget') {
this.progressReport_.errors.push(error);
this.logger().warn('Rejected by target: ' + path + ': ' + error.message);
continue;
} else {
throw error;
}
}
if (!remoteContent) throw new Error("Got metadata for path but could not fetch content: " + path);
remoteContent = await BaseItem.unserialize(remoteContent);

Expand Down Expand Up @@ -485,26 +495,37 @@ class Synchronizer {
let local = await BaseItem.loadItemByPath(path);
let ItemClass = null;
let content = null;
if (!local) {
if (remote.isDeleted !== true) {
action = "createLocal";
reason = "remote exists but local does not";
content = await loadContent();
ItemClass = content ? BaseItem.itemClass(content) : null;
}
} else {
ItemClass = BaseItem.itemClass(local);
local = ItemClass.filter(local);
if (remote.isDeleted) {
action = "deleteLocal";
reason = "remote has been deleted";

try {
if (!local) {
if (remote.isDeleted !== true) {
action = "createLocal";
reason = "remote exists but local does not";
content = await loadContent();
ItemClass = content ? BaseItem.itemClass(content) : null;
}
} else {
content = await loadContent();
if (content && content.updated_time > local.updated_time) {
action = "updateLocal";
reason = "remote is more recent than local";
ItemClass = BaseItem.itemClass(local);
local = ItemClass.filter(local);
if (remote.isDeleted) {
action = "deleteLocal";
reason = "remote has been deleted";
} else {
content = await loadContent();
if (content && content.updated_time > local.updated_time) {
action = "updateLocal";
reason = "remote is more recent than local";
}
}
}
} catch (error) {
if (error.code === 'rejectedByTarget') {
this.progressReport_.errors.push(error);
this.logger().warn('Rejected by target: ' + path + ': ' + error.message);
action = null;
} else {
throw error;
}
}

if (!action) continue;
Expand Down Expand Up @@ -536,7 +557,17 @@ class Synchronizer {
if (content.type_ == BaseModel.TYPE_RESOURCE && action == "createLocal") {
let localResourceContentPath = Resource.fullPath(content);
let remoteResourceContentPath = this.resourceDirName_ + "/" + content.id;
await this.api().get(remoteResourceContentPath, { path: localResourceContentPath, target: "file" });
try {
await this.api().get(remoteResourceContentPath, { path: localResourceContentPath, target: "file" });
} catch (error) {
if (error.code === 'rejectedByTarget') {
this.progressReport_.errors.push(error);
this.logger().warn('Rejected by target: ' + path + ': ' + error.message);
continue;
} else {
throw error;
}
}
}

await ItemClass.save(content, options);
Expand Down

0 comments on commit a8b58aa

Please sign in to comment.