/** * Check if a file exists in the OC server * * @deprecated Use ExistenceCheckOperation instead * * @return 'true' if the file exists; 'false' it doesn't exist * @throws Exception When the existence could not be determined */ @Deprecated public boolean existsFile(String path) throws IOException { HeadMethod head = new HeadMethod(getWebdavUri() + WebdavUtils.encodePath(path)); try { int status = executeMethod(head); Log_OC.d(TAG, "HEAD to " + path + " finished with HTTP status " + status + ((status != HttpStatus.SC_OK)?"(FAIL)":"")); exhaustResponse(head.getResponseBodyAsStream()); return (status == HttpStatus.SC_OK); } finally { head.releaseConnection(); // let the connection available for other methods } }
try { copyMethod = new CopyMethod( client.getWebdavUri() + WebdavUtils.encodePath(mSrcRemotePath), client.getWebdavUri() + WebdavUtils.encodePath(mTargetRemotePath), mOverwrite );
/** * Performs the rename operation. * * @param client Client object to communicate with the remote ownCloud server. */ @Override protected RemoteOperationResult run(OwnCloudClient client) { RemoteOperationResult result; try { Uri srcWebDavUri = removeChunksFolder ? client.getUploadsWebDavUri() : client.getUserFilesWebDavUri(); DeleteMethod deleteMethod = new DeleteMethod( new URL(srcWebDavUri + WebdavUtils.encodePath(mRemotePath))); int status = client.executeHttpMethod(deleteMethod); result = isSuccess(status) ? new RemoteOperationResult<>(OK) : new RemoteOperationResult<>(deleteMethod); Log_OC.i(TAG, "Remove " + mRemotePath + ": " + result.getLogMessage()); } catch (Exception e) { result = new RemoteOperationResult<>(e); Log_OC.e(TAG, "Remove " + mRemotePath + ": " + result.getLogMessage(), e); } return result; }
String stringUrl = mIsLogin ? client.getBaseFilesWebDavUri().toString() : client.getUserFilesWebDavUri() + WebdavUtils.encodePath(mPath); PropfindMethod propfindMethod = new PropfindMethod( new URL(stringUrl), Log_OC.d(TAG, "Existence check for " + stringUrl + WebdavUtils.encodePath(mPath) + " targeting for " + (mSuccessIfAbsent ? " absence " : " existence ") + "finished with HTTP status " + status + (!isSuccess(status) ? "(FAIL)" : "")); final RemoteOperationResult result = new RemoteOperationResult<>(e); Log_OC.e(TAG, "Existence check for " + client.getUserFilesWebDavUri() + WebdavUtils.encodePath(mPath) + " targeting for " + (mSuccessIfAbsent ? " absence " : " existence ") + ": " + result.getLogMessage(), result.getException());
/** * Performs the operation. * * @param client Client object to communicate with the remote ownCloud server. */ @Override protected RemoteOperationResult run(OwnCloudClient client) { RemoteOperationResult result; try { String source = client.getNewWebdavUri() + WebdavUtils.encodePath(sourcePath); String target = client.getNewWebdavUri() + "/trashbin/" + userId + "/restore/" + fileName; MoveMethod move = new MoveMethod(source, target, true); int status = client.executeMethod(move, RESTORE_READ_TIMEOUT, RESTORE_CONNECTION_TIMEOUT); result = new RemoteOperationResult(isSuccess(status), move); client.exhaustResponse(move.getResponseBodyAsStream()); } catch (IOException e) { result = new RemoteOperationResult(e); Log.e(TAG, "Restore trashbin file " + sourcePath + " failed: " + result.getLogMessage(), e); } return result; }
new URL(srcWebDavUri + WebdavUtils.encodePath(mSrcRemotePath)), client.getUserFilesWebDavUri() + WebdavUtils.encodePath(mTargetRemotePath), mOverwrite);
private RemoteOperationResult createFolder(OwnCloudClient client) { RemoteOperationResult result; try { Uri webDavUri = createChunksFolder ? client.getUploadsWebDavUri() : client.getUserFilesWebDavUri(); final MkColMethod mkcol = new MkColMethod(new URL(webDavUri + WebdavUtils.encodePath(mRemotePath))); mkcol.setReadTimeout(READ_TIMEOUT, TimeUnit.SECONDS); mkcol.setConnectionTimeout(CONNECTION_TIMEOUT, TimeUnit.SECONDS); final int status = client.executeHttpMethod(mkcol); result = (status == HttpConstants.HTTP_CREATED) ? new RemoteOperationResult<>(ResultCode.OK) : new RemoteOperationResult<>(mkcol); Log_OC.d(TAG, "Create directory " + mRemotePath + ": " + result.getLogMessage()); client.exhaustResponse(mkcol.getResponseBodyAsStream()); } catch (Exception e) { result = new RemoteOperationResult<>(e); Log_OC.e(TAG, "Create directory " + mRemotePath + ": " + result.getLogMessage(), e); } return result; }
WebdavUtils.encodePath(mOldRemotePath)), client.getUserFilesWebDavUri() + WebdavUtils.encodePath(mNewRemotePath), false);
propSet.add(DavPropertyName.GETETAG); PropFindMethod propfind = new PropFindMethod(client.getWebdavUri() + WebdavUtils.encodePath(path), propSet, 0); int status = client.executeMethod(propfind, SYNC_READ_TIMEOUT, SYNC_CONNECTION_TIMEOUT);
boolean previousFollowRedirects = client.getFollowRedirects(); try { head = new HeadMethod(client.getWebdavUri() + WebdavUtils.encodePath(mPath)); client.setFollowRedirects(false); int status = client.executeMethod(head, TIMEOUT, TIMEOUT); ); Log_OC.d(TAG, "Existence check for " + client.getWebdavUri() + WebdavUtils.encodePath(mPath) + " targeting for " + (mSuccessIfAbsent ? " absence " : " existence ") + "finished with HTTP status " + status + (!success?"(FAIL)":"")); result = new RemoteOperationResult(e); Log_OC.e(TAG, "Existence check for " + client.getWebdavUri() + WebdavUtils.encodePath(mPath) + " targeting for " + (mSuccessIfAbsent ? " absence " : " existence ") + ": " + result.getLogMessage(), result.getException());
move = new MoveMethod(client.getWebdavUri() + WebdavUtils.encodePath(mOldRemotePath), client.getWebdavUri() + WebdavUtils.encodePath(mNewRemotePath), true); client.executeMethod(move, RENAME_READ_TIMEOUT, RENAME_CONNECTION_TIMEOUT); result = new RemoteOperationResult(move.succeeded(), move);
propfind = new PropfindMethod(new URL(client.getUserFilesWebDavUri() + WebdavUtils.encodePath(mRemotePath)), DEPTH_0, DavUtils.getAllPropset());
@Override protected RemoteOperationResult run(OwnCloudClient client) { RemoteOperationResult result; try { mPutMethod = new PutMethod( new URL(client.getUserFilesWebDavUri() + WebdavUtils.encodePath(mRemotePath))); mPutMethod.setRetryOnConnectionFailure(false); if (mCancellationRequested.get()) { // the operation was cancelled before getting it's turn to be executed in the queue of uploads result = new RemoteOperationResult<>(new OperationCancelledException()); } else { // perform the upload result = uploadFile(client); Log_OC.i(TAG, "Upload of " + mLocalPath + " to " + mRemotePath + ": " + result.getLogMessage()); } } catch (Exception e) { if (mPutMethod != null && mPutMethod.isAborted()) { result = new RemoteOperationResult<>(new OperationCancelledException()); Log_OC.e(TAG, "Upload of " + mLocalPath + " to " + mRemotePath + ": " + result.getLogMessage(), new OperationCancelledException()); } else { result = new RemoteOperationResult<>(e); Log_OC.e(TAG, "Upload of " + mLocalPath + " to " + mRemotePath + ": " + result.getLogMessage(), e); } } return result; }
new URL(client.getUserFilesWebDavUri() + WebdavUtils.encodePath(mRemotePath)), DavConstants.DEPTH_1, DavUtils.getAllPropset());
propfind = new PropFindMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath),
/** * Performs the remove operation. * * @param client Client object to communicate with the remote ownCloud server. */ @Override protected RemoteOperationResult run(OwnCloudClient client) { RemoteOperationResult result; DeleteMethod delete = null; try { delete = new DeleteMethod(client.getNewWebdavUri() + WebdavUtils.encodePath(remotePath)); int status = client.executeMethod(delete, REMOVE_READ_TIMEOUT, REMOVE_CONNECTION_TIMEOUT); delete.getResponseBodyAsString(); // exhaust the response, although not interesting result = new RemoteOperationResult((delete.succeeded() || status == HttpStatus.SC_NOT_FOUND), delete); Log_OC.i(TAG, "Remove " + remotePath + ": " + result.getLogMessage()); } catch (Exception e) { result = new RemoteOperationResult(e); Log_OC.e(TAG, "Remove " + remotePath + ": " + result.getLogMessage(), e); } finally { if (delete != null) delete.releaseConnection(); } return result; } }
/** * Performs the rename operation. * * @param client Client object to communicate with the remote ownCloud server. */ @Override protected RemoteOperationResult run(OwnCloudClient client) { RemoteOperationResult result = null; DeleteMethod delete = null; try { delete = new DeleteMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath)); int status = client.executeMethod(delete, REMOVE_READ_TIMEOUT, REMOVE_CONNECTION_TIMEOUT); delete.getResponseBodyAsString(); // exhaust the response, although not interesting result = new RemoteOperationResult( (delete.succeeded() || status == HttpStatus.SC_NOT_FOUND), delete ); Log_OC.i(TAG, "Remove " + mRemotePath + ": " + result.getLogMessage()); } catch (Exception e) { result = new RemoteOperationResult(e); Log_OC.e(TAG, "Remove " + mRemotePath + ": " + result.getLogMessage(), e); } finally { if (delete != null) delete.releaseConnection(); } return result; }
new URL(client.getUserFilesWebDavUri() + WebdavUtils.encodePath(mRemotePath)), DEPTH_0, DavUtils.getQuotaPropSet());
); putMethod = new PutMethod(client.getWebdavUri() + WebdavUtils.encodePath(remotePath));
private RemoteOperationResult createFolder(OwnCloudClient client) { RemoteOperationResult result; MkColMethod mkCol = null; try { mkCol = new MkColMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath)); client.setUseNextcloudUserAgent(true); client.executeMethod(mkCol, READ_TIMEOUT, CONNECTION_TIMEOUT); if (HttpStatus.SC_METHOD_NOT_ALLOWED == mkCol.getStatusCode()) { result = new RemoteOperationResult(RemoteOperationResult.ResultCode.FOLDER_ALREADY_EXISTS); } else { result = new RemoteOperationResult(mkCol.succeeded(), mkCol); } Log_OC.d(TAG, "Create directory " + mRemotePath + ": " + result.getLogMessage()); client.exhaustResponse(mkCol.getResponseBodyAsStream()); } catch (Exception e) { result = new RemoteOperationResult(e); Log_OC.e(TAG, "Create directory " + mRemotePath + ": " + result.getLogMessage(), e); } finally { if (mkCol != null) mkCol.releaseConnection(); } return result; }