@Override public void removeDirectory(OCFile dir, boolean removeDBData, boolean removeLocalContent) { // TODO consider possible failures if (dir != null && dir.isDirectory() && dir.getFileId() != -1) { Vector<OCFile> children = getDirectoryContent(dir); if (children.size() > 0) { OCFile child = null; for (int i = 0; i < children.size(); i++) { child = children.get(i); if (child.isDirectory()) { removeDirectory(child, removeDBData, removeLocalContent); } else { if (removeDBData) { removeFile(child, removeLocalContent); } else if (removeLocalContent) { if (child.isDown()) { new File(child.getStoragePath()).delete(); } } } } } if (removeDBData) { removeFile(dir, true); } if (dir.getFileLength() > 0) { updateSizesToTheRoot(dir.getParentId()); } } }
public void run() { WebdavClient wc = OwnCloudClientUtils.createOwnCloudClient( mAccount, getSherlockActivity().getApplicationContext()); AccountManager am = AccountManager.get(getSherlockActivity()); String baseUrl = am.getUserData(mAccount, AccountAuthenticator.KEY_OC_BASE_URL); OwnCloudVersion ocv = new OwnCloudVersion(am.getUserData(mAccount, AccountAuthenticator.KEY_OC_VERSION)); String webdav_path = AccountUtils.getWebdavPath(ocv); Log.d("ASD", "" + baseUrl + webdav_path + WebdavUtils.encodePath(mOld.getRemotePath())); Log.e( "ASD", Uri.parse(baseUrl).getPath() == null ? "" : Uri.parse(baseUrl).getPath() + webdav_path + WebdavUtils.encodePath(mNew.getRemotePath())); LocalMoveMethod move = new LocalMoveMethod( baseUrl + webdav_path + WebdavUtils.encodePath(mOld.getRemotePath()), Uri.parse(baseUrl).getPath() == null ? "" : Uri.parse(baseUrl).getPath() + webdav_path + WebdavUtils.encodePath(mNew.getRemotePath())); boolean success = false; try { int status = wc.executeMethod(move); success = move.succeeded(); move.getResponseBodyAsString(); // exhaust response, although not interesting Log.d(TAG, "Move returned status: " + status); } catch (HttpException e) { Log.e( TAG, "HTTP Exception renaming file " + mOld.getRemotePath() + " to " + mNew.getRemotePath(), e); } catch (IOException e) { Log.e( TAG, "I/O Exception renaming file " + mOld.getRemotePath() + " to " + mNew.getRemotePath(), e); } catch (Exception e) { Log.e( TAG, "Unexpected exception renaming file " + mOld.getRemotePath() + " to " + mNew.getRemotePath(), e); } finally { move.releaseConnection(); } if (success) { FileDataStorageManager fdsm = new FileDataStorageManager(mAccount, getActivity().getContentResolver()); fdsm.removeFile(mOld, false); fdsm.saveFile(mNew); mFile = mNew; mHandler.post( new Runnable() { @Override public void run() { boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity; getActivity() .dismissDialog( (inDisplayActivity) ? FileDisplayActivity.DIALOG_SHORT_WAIT : FileDetailActivity.DIALOG_SHORT_WAIT); updateFileDetails(mFile, mAccount); mContainerActivity.onFileStateChanged(); } }); } else { mHandler.post( new Runnable() { @Override public void run() { // undo the local rename if (mNew.isDown()) { File f = new File(mNew.getStoragePath()); if (!f.renameTo(new File(mOld.getStoragePath()))) { // the local rename undoing failed; last chance: save the new local storage path // in the old file mFile.setStoragePath(mNew.getStoragePath()); FileDataStorageManager fdsm = new FileDataStorageManager(mAccount, getActivity().getContentResolver()); fdsm.saveFile(mFile); } } boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity; getActivity() .dismissDialog( (inDisplayActivity) ? FileDisplayActivity.DIALOG_SHORT_WAIT : FileDetailActivity.DIALOG_SHORT_WAIT); try { Toast msg = Toast.makeText( getActivity(), R.string.rename_server_fail_msg, Toast.LENGTH_LONG); msg.show(); } catch (NotFoundException e) { e.printStackTrace(); } } }); } }
public void run() { WebdavClient wc = OwnCloudClientUtils.createOwnCloudClient( mAccount, getSherlockActivity().getApplicationContext()); AccountManager am = AccountManager.get(getSherlockActivity()); String baseUrl = am.getUserData(mAccount, AccountAuthenticator.KEY_OC_BASE_URL); OwnCloudVersion ocv = new OwnCloudVersion(am.getUserData(mAccount, AccountAuthenticator.KEY_OC_VERSION)); String webdav_path = AccountUtils.getWebdavPath(ocv); Log.d( "ASD", "" + baseUrl + webdav_path + WebdavUtils.encodePath(mFileToRemove.getRemotePath())); DeleteMethod delete = new DeleteMethod( baseUrl + webdav_path + WebdavUtils.encodePath(mFileToRemove.getRemotePath())); boolean success = false; int status = -1; try { status = wc.executeMethod(delete); success = (delete.succeeded()); delete.getResponseBodyAsString(); // exhaust the response, although not interesting Log.d(TAG, "Delete: returned status " + status); } catch (HttpException e) { Log.e(TAG, "HTTP Exception removing file " + mFileToRemove.getRemotePath(), e); } catch (IOException e) { Log.e(TAG, "I/O Exception removing file " + mFileToRemove.getRemotePath(), e); } catch (Exception e) { Log.e(TAG, "Unexpected exception removing file " + mFileToRemove.getRemotePath(), e); } finally { delete.releaseConnection(); } if (success) { FileDataStorageManager fdsm = new FileDataStorageManager(mAccount, getActivity().getContentResolver()); fdsm.removeFile(mFileToRemove, true); mHandler.post( new Runnable() { @Override public void run() { boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity; getActivity() .dismissDialog( (inDisplayActivity) ? FileDisplayActivity.DIALOG_SHORT_WAIT : FileDetailActivity.DIALOG_SHORT_WAIT); try { Toast msg = Toast.makeText( getActivity().getApplicationContext(), R.string.remove_success_msg, Toast.LENGTH_LONG); msg.show(); if (inDisplayActivity) { // double pane FragmentTransaction transaction = getActivity().getSupportFragmentManager().beginTransaction(); transaction.replace( R.id.file_details_container, new FileDetailFragment(null, null)); // empty FileDetailFragment transaction.commit(); mContainerActivity.onFileStateChanged(); } else { getActivity().finish(); } } catch (NotFoundException e) { e.printStackTrace(); } } }); } else { mHandler.post( new Runnable() { @Override public void run() { boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity; getActivity() .dismissDialog( (inDisplayActivity) ? FileDisplayActivity.DIALOG_SHORT_WAIT : FileDetailActivity.DIALOG_SHORT_WAIT); try { Toast msg = Toast.makeText(getActivity(), R.string.remove_fail_msg, Toast.LENGTH_LONG); msg.show(); } catch (NotFoundException e) { e.printStackTrace(); } } }); } }