|
@@ -1,7 +1,5 @@
|
|
package com.owncloud.android.oc_framework.operations.remote;
|
|
package com.owncloud.android.oc_framework.operations.remote;
|
|
|
|
|
|
-import java.io.File;
|
|
|
|
-
|
|
|
|
import org.apache.commons.httpclient.HttpStatus;
|
|
import org.apache.commons.httpclient.HttpStatus;
|
|
import org.apache.jackrabbit.webdav.client.methods.MkColMethod;
|
|
import org.apache.jackrabbit.webdav.client.methods.MkColMethod;
|
|
|
|
|
|
@@ -11,6 +9,8 @@ import com.owncloud.android.oc_framework.network.webdav.WebdavClient;
|
|
import com.owncloud.android.oc_framework.network.webdav.WebdavUtils;
|
|
import com.owncloud.android.oc_framework.network.webdav.WebdavUtils;
|
|
import com.owncloud.android.oc_framework.operations.RemoteOperation;
|
|
import com.owncloud.android.oc_framework.operations.RemoteOperation;
|
|
import com.owncloud.android.oc_framework.operations.RemoteOperationResult;
|
|
import com.owncloud.android.oc_framework.operations.RemoteOperationResult;
|
|
|
|
+import com.owncloud.android.oc_framework.operations.RemoteOperationResult.ResultCode;
|
|
|
|
+import com.owncloud.android.oc_framework.utils.FileUtils;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -28,7 +28,7 @@ public class CreateRemoteFolderOperation extends RemoteOperation {
|
|
private static final int READ_TIMEOUT = 10000;
|
|
private static final int READ_TIMEOUT = 10000;
|
|
private static final int CONNECTION_TIMEOUT = 5000;
|
|
private static final int CONNECTION_TIMEOUT = 5000;
|
|
|
|
|
|
- private static final String PATH_SEPARATOR = "/";
|
|
|
|
|
|
+
|
|
|
|
|
|
protected String mRemotePath;
|
|
protected String mRemotePath;
|
|
protected boolean mCreateFullPath;
|
|
protected boolean mCreateFullPath;
|
|
@@ -54,26 +54,32 @@ public class CreateRemoteFolderOperation extends RemoteOperation {
|
|
RemoteOperationResult result = null;
|
|
RemoteOperationResult result = null;
|
|
MkColMethod mkcol = null;
|
|
MkColMethod mkcol = null;
|
|
|
|
|
|
- try {
|
|
|
|
- mkcol = new MkColMethod(client.getBaseUri() + WebdavUtils.encodePath(mRemotePath));
|
|
|
|
- int status = client.executeMethod(mkcol, READ_TIMEOUT, CONNECTION_TIMEOUT);
|
|
|
|
- if (!mkcol.succeeded() && mkcol.getStatusCode() == HttpStatus.SC_CONFLICT && mCreateFullPath) {
|
|
|
|
- result = createParentFolder(getParentPath(), client);
|
|
|
|
- status = client.executeMethod(mkcol, READ_TIMEOUT, CONNECTION_TIMEOUT); // second (and last) try
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- result = new RemoteOperationResult(mkcol.succeeded(), status, mkcol.getResponseHeaders());
|
|
|
|
- Log.d(TAG, "Create directory " + mRemotePath + ": " + result.getLogMessage());
|
|
|
|
- client.exhaustResponse(mkcol.getResponseBodyAsStream());
|
|
|
|
-
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- result = new RemoteOperationResult(e);
|
|
|
|
- Log.e(TAG, "Create directory " + mRemotePath + ": " + result.getLogMessage(), e);
|
|
|
|
-
|
|
|
|
- } finally {
|
|
|
|
- if (mkcol != null)
|
|
|
|
- mkcol.releaseConnection();
|
|
|
|
|
|
+ boolean noInvalidChars = FileUtils.validateName(mRemotePath);
|
|
|
|
+ if (noInvalidChars) {
|
|
|
|
+ try {
|
|
|
|
+ mkcol = new MkColMethod(client.getBaseUri() + WebdavUtils.encodePath(mRemotePath));
|
|
|
|
+ int status = client.executeMethod(mkcol, READ_TIMEOUT, CONNECTION_TIMEOUT);
|
|
|
|
+ if (!mkcol.succeeded() && mkcol.getStatusCode() == HttpStatus.SC_CONFLICT && mCreateFullPath) {
|
|
|
|
+ result = createParentFolder(FileUtils.getParentPath(mRemotePath), client);
|
|
|
|
+ status = client.executeMethod(mkcol, READ_TIMEOUT, CONNECTION_TIMEOUT); // second (and last) try
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ result = new RemoteOperationResult(mkcol.succeeded(), status, mkcol.getResponseHeaders());
|
|
|
|
+ Log.d(TAG, "Create directory " + mRemotePath + ": " + result.getLogMessage());
|
|
|
|
+ client.exhaustResponse(mkcol.getResponseBodyAsStream());
|
|
|
|
+
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ result = new RemoteOperationResult(e);
|
|
|
|
+ Log.e(TAG, "Create directory " + mRemotePath + ": " + result.getLogMessage(), e);
|
|
|
|
+
|
|
|
|
+ } finally {
|
|
|
|
+ if (mkcol != null)
|
|
|
|
+ mkcol.releaseConnection();
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ result = new RemoteOperationResult(ResultCode.INVALID_CHARACTER_IN_NAME);
|
|
}
|
|
}
|
|
|
|
+
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -84,10 +90,6 @@ public class CreateRemoteFolderOperation extends RemoteOperation {
|
|
return operation.execute(client);
|
|
return operation.execute(client);
|
|
}
|
|
}
|
|
|
|
|
|
- private String getParentPath() {
|
|
|
|
- String parentPath = new File(mRemotePath).getParent();
|
|
|
|
- parentPath = parentPath.endsWith(PATH_SEPARATOR) ? parentPath : parentPath + PATH_SEPARATOR;
|
|
|
|
- return parentPath;
|
|
|
|
- }
|
|
|
|
|
|
+
|
|
|
|
|
|
}
|
|
}
|