1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-11-29 22:48:10 +02:00

All: Fixed: Prevent app from trying to upload resource it has not downloaded yet

This commit is contained in:
Laurent Cozic
2019-05-16 17:34:16 +00:00
parent 8ebaa7f6eb
commit 1a091460ca
3 changed files with 66 additions and 18 deletions

View File

@@ -99,12 +99,15 @@ class ResourceFetcher extends BaseService {
if (this.fetchingItems_[resourceId]) return;
this.fetchingItems_[resourceId] = true;
const resource = await Resource.load(resourceId);
const localState = await Resource.localState(resource);
const completeDownload = async (emitDownloadComplete = true, localResourceContentPath = '') => {
// 2019-05-12: This is only necessary to set the file size of the resources that come via
// sync. The other ones have been done using migrations/20.js. This code can be removed
// after a few months.
if (resource.size < 0 && localResourceContentPath && !resource.encryption_blob_encrypted) {
if (resource && resource.size < 0 && localResourceContentPath && !resource.encryption_blob_encrypted) {
await ResourceService.autoSetFileSizes();
}
@@ -119,8 +122,11 @@ class ResourceFetcher extends BaseService {
this.updateReport();
}
const resource = await Resource.load(resourceId);
const localState = await Resource.localState(resource);
if (!resource) {
this.logger().info('ResourceFetcher: Attempting to download a resource that does not exist (has been deleted?): ' + resourceId);
await completeDownload(false);
return;
}
// Shouldn't happen, but just to be safe don't re-download the
// resource if it's already been downloaded.
@@ -166,7 +172,7 @@ class ResourceFetcher extends BaseService {
async waitForAllFinished() {
return new Promise((resolve, reject) => {
const iid = setInterval(() => {
if (!this.queue_.length && !Object.getOwnPropertyNames(this.fetchingItems_).length) {
if (!this.updateReportIID_ && !this.scheduleQueueProcessIID_ && !this.addingResources_ && !this.queue_.length && !Object.getOwnPropertyNames(this.fetchingItems_).length) {
clearInterval(iid);
resolve();
}

View File

@@ -231,6 +231,11 @@ class Synchronizer {
if (syncSteps.indexOf("update_remote") >= 0) {
let donePaths = [];
const completeItemProcessing = (path) => {
donePaths.push(path);
}
while (true) {
if (this.cancelling()) break;
@@ -290,6 +295,7 @@ class Synchronizer {
if (error.code === 'rejectedByTarget') {
this.progressReport_.errors.push(error);
this.logger().warn('Rejected by target: ' + path + ': ' + error.message);
completeItemProcessing(path);
continue;
} else {
throw error;
@@ -313,18 +319,23 @@ class Synchronizer {
this.logSyncOperation(action, local, remote, reason);
if (local.type_ == BaseModel.TYPE_RESOURCE && (action == "createRemote" || action === "updateRemote" || (action == "itemConflict" && remote))) {
try {
const remoteContentPath = this.resourceDirName_ + "/" + local.id;
const result = await Resource.fullPathForSyncUpload(local);
local = result.resource;
const localResourceContentPath = result.path;
await this.api().put(remoteContentPath, null, { path: localResourceContentPath, source: "file" });
} catch (error) {
if (error && ["rejectedByTarget", "fileNotFound"].indexOf(error.code) >= 0) {
await handleCannotSyncItem(ItemClass, syncTargetId, local, error.message);
action = null;
} else {
throw error;
const localState = await Resource.localState(local.id);
if (localState.fetch_status !== Resource.FETCH_STATUS_DONE) {
action = null;
} else {
try {
const remoteContentPath = this.resourceDirName_ + "/" + local.id;
const result = await Resource.fullPathForSyncUpload(local);
local = result.resource;
const localResourceContentPath = result.path;
await this.api().put(remoteContentPath, null, { path: localResourceContentPath, source: "file" });
} catch (error) {
if (error && ["rejectedByTarget", "fileNotFound"].indexOf(error.code) >= 0) {
await handleCannotSyncItem(ItemClass, syncTargetId, local, error.message);
action = null;
} else {
throw error;
}
}
}
}
@@ -422,7 +433,7 @@ class Synchronizer {
}
}
donePaths.push(path);
completeItemProcessing(path);
}
if (!result.hasMore) break;