Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.owncloud.android.lib.common.OwnCloudClientFactory;
import com.owncloud.android.lib.common.OwnCloudCredentialsFactory;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.resources.files.CreateRemoteFolderOperation;
import com.owncloud.android.lib.resources.files.DownloadRemoteFileOperation;
import com.owncloud.android.lib.resources.files.ExistenceCheckRemoteOperation;
import com.owncloud.android.lib.resources.files.FileUtils;
Expand Down Expand Up @@ -218,6 +219,11 @@ private void createNote(Note note) {
// don't destroy anything, create a new entry and let the user resolve the conflict
note.filename = generateNewFileName(note.filename);
createNote(note);
} else if (result.getCode().equals(RemoteOperationResult.ResultCode.FILE_NOT_FOUND)) {
// target folder not found... create and retry
if (createFolder(remotePath.substring(0, remotePath.lastIndexOf("/")))) {
createNote(note);
}
} else {
handleError(result);
}
Expand All @@ -235,7 +241,17 @@ private void createNote(Note note) {
}

mContext.getContentResolver().update(NotesProvider.NOTES.withId(note.id), note.getContentValues(), null, null);
}
}

private boolean createFolder(String folder) {
CreateRemoteFolderOperation createRemoteFolderOperation = new CreateRemoteFolderOperation(folder, false);
RemoteOperationResult result = createRemoteFolderOperation.execute(mClient);
if (!result.isSuccess()) {
handleError(result);
return false;
}
return true;
}

private String generateNewFileName(String name) {
Expand Down