You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2018/12/04 08:27:57 UTC
[camel] 07/08: [CAMEL-12942] Fix dropbox put operation
This is an automated email from the ASF dual-hosted git repository.
acosentino pushed a commit to branch sandbox/camel-3.x
in repository https://gitbox.apache.org/repos/asf/camel.git
commit bb4504d67f9ddcdd7a5670531e9ed74cb34cdf81
Author: Jan <jb...@redhat.com>
AuthorDate: Fri Nov 16 09:14:20 2018 +0100
[CAMEL-12942] Fix dropbox put operation
---
.../component/dropbox/core/DropboxAPIFacade.java | 24 +++++++++++-----------
1 file changed, 12 insertions(+), 12 deletions(-)
diff --git a/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/core/DropboxAPIFacade.java b/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/core/DropboxAPIFacade.java
index 1b43179..d6e3c7b 100644
--- a/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/core/DropboxAPIFacade.java
+++ b/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/core/DropboxAPIFacade.java
@@ -92,31 +92,31 @@ public final class DropboxAPIFacade {
// in case the remote path is not specified, the remotePath = localPath
String dropboxPath = remotePath == null ? localPath : remotePath;
- UploadUploader entry;
+ boolean isPresent = true;
try {
- entry = client.files().upload(dropboxPath);
+ client.files().getMetadata(dropboxPath);
} catch (DbxException e) {
- throw new DropboxException(dropboxPath + " does not exist or cannot obtain metadata", e);
+ isPresent = false;
}
if (localPath != null) {
- return putFile(localPath, mode, dropboxPath, entry);
+ return putFile(localPath, mode, dropboxPath, isPresent);
} else {
- return putBody(exchange, mode, dropboxPath, entry);
+ return putBody(exchange, mode, dropboxPath, isPresent);
}
}
- private DropboxFileUploadResult putFile(String localPath, DropboxUploadMode mode, String dropboxPath, UploadUploader entry) throws DropboxException {
+ private DropboxFileUploadResult putFile(String localPath, DropboxUploadMode mode, String dropboxPath, boolean isPresent) throws DropboxException {
File fileLocalPath = new File(localPath);
// verify uploading of a single file
if (fileLocalPath.isFile()) {
// check if dropbox file exists
- if (entry != null && !DropboxUploadMode.force.equals(mode)) {
- throw new DropboxException(dropboxPath + " exists on dropbox and is not a file!");
+ if (isPresent && !DropboxUploadMode.force.equals(mode)) {
+ throw new DropboxException(dropboxPath + " exists on dropbox. Use force upload mode to override");
}
// in case the entry not exists on dropbox check if the filename
// should be appended
- if (entry == null) {
+ if (!isPresent) {
if (dropboxPath.endsWith(DropboxConstants.DROPBOX_FILE_SEPARATOR)) {
dropboxPath = dropboxPath + fileLocalPath.getName();
}
@@ -139,7 +139,7 @@ public final class DropboxAPIFacade {
// verify uploading of a list of files inside a dir
LOG.debug("Uploading a dir...");
// check if dropbox folder exists
- if (entry != null && !DropboxUploadMode.force.equals(mode)) {
+ if (isPresent && !DropboxUploadMode.force.equals(mode)) {
throw new DropboxException(dropboxPath + " exists on dropbox and is not a folder!");
}
if (!dropboxPath.endsWith(DropboxConstants.DROPBOX_FILE_SEPARATOR)) {
@@ -181,7 +181,7 @@ public final class DropboxAPIFacade {
}
}
- private DropboxFileUploadResult putBody(Exchange exchange, DropboxUploadMode mode, String dropboxPath, UploadUploader entry) throws DropboxException {
+ private DropboxFileUploadResult putBody(Exchange exchange, DropboxUploadMode mode, String dropboxPath, boolean isPresent) throws DropboxException {
String name = exchange.getIn().getHeader(HEADER_PUT_FILE_NAME, String.class);
if (name == null) {
// fallback to use CamelFileName
@@ -194,7 +194,7 @@ public final class DropboxAPIFacade {
// in case the entry not exists on dropbox check if the filename should
// be appended
- if (entry == null) {
+ if (!isPresent) {
if (dropboxPath.endsWith(DropboxConstants.DROPBOX_FILE_SEPARATOR)) {
dropboxPath = dropboxPath + name;
}