mirror of
https://github.com/owncloud/android-library.git
synced 2025-06-08 00:16:09 +00:00
Delete remote chunks folder when canceling upload
This commit is contained in:
parent
78613ed4bc
commit
f1c6726d30
@ -57,7 +57,7 @@ public class CreateRemoteFolderOperation extends RemoteOperation {
|
||||
|
||||
private String mRemotePath;
|
||||
private boolean mCreateFullPath;
|
||||
protected boolean mFolderToSaveChunks;
|
||||
protected boolean createChunksFolder;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
@ -67,7 +67,7 @@ public class CreateRemoteFolderOperation extends RemoteOperation {
|
||||
public CreateRemoteFolderOperation(String remotePath, boolean createFullPath) {
|
||||
mRemotePath = remotePath;
|
||||
mCreateFullPath = createFullPath;
|
||||
mFolderToSaveChunks = false;
|
||||
createChunksFolder = false;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -103,7 +103,7 @@ public class CreateRemoteFolderOperation extends RemoteOperation {
|
||||
private RemoteOperationResult createFolder(OwnCloudClient client) {
|
||||
RemoteOperationResult result;
|
||||
try {
|
||||
Uri webDavUri = mFolderToSaveChunks ? client.getNewUploadsWebDavUri() : client.getNewFilesWebDavUri();
|
||||
Uri webDavUri = createChunksFolder ? client.getNewUploadsWebDavUri() : client.getNewFilesWebDavUri();
|
||||
final MkColMethod mkcol = new MkColMethod(HttpUrl.parse(webDavUri + WebdavUtils.encodePath(mRemotePath)));
|
||||
mkcol.setReadTimeout(READ_TIMEOUT, TimeUnit.SECONDS);
|
||||
mkcol.setConnectionTimeout(CONNECTION_TIMEOUT, TimeUnit.SECONDS);
|
||||
|
@ -1,19 +0,0 @@
|
||||
package com.owncloud.android.lib.resources.files;
|
||||
|
||||
public class MoveRemoteChunksFileOperation extends MoveRemoteFileOperation {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param srcRemotePath Remote path of the file/folder to move.
|
||||
* @param targetRemotePath Remove path desired for the file/folder after moving it.
|
||||
* @param overwrite
|
||||
*/
|
||||
public MoveRemoteChunksFileOperation(String srcRemotePath, String targetRemotePath, boolean overwrite,
|
||||
String fileLastModifTimestamp, long fileLength) {
|
||||
super(srcRemotePath, targetRemotePath, overwrite);
|
||||
isChunkedFile = true;
|
||||
mFileLastModifTimestamp = fileLastModifTimestamp;
|
||||
mFileLength = fileLength;
|
||||
}
|
||||
}
|
@ -60,7 +60,7 @@ public class MoveRemoteFileOperation extends RemoteOperation {
|
||||
private String mTargetRemotePath;
|
||||
private boolean mOverwrite;
|
||||
|
||||
protected boolean isChunkedFile;
|
||||
protected boolean moveChunkedFile = false;
|
||||
protected String mFileLastModifTimestamp;
|
||||
protected long mFileLength;
|
||||
|
||||
@ -79,7 +79,6 @@ public class MoveRemoteFileOperation extends RemoteOperation {
|
||||
mSrcRemotePath = srcRemotePath;
|
||||
mTargetRemotePath = targetRemotePath;
|
||||
mOverwrite = overwrite;
|
||||
isChunkedFile = false;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -111,17 +110,16 @@ public class MoveRemoteFileOperation extends RemoteOperation {
|
||||
/// perform remote operation
|
||||
RemoteOperationResult result;
|
||||
try {
|
||||
|
||||
// After finishing a chunked upload, we have to move the resulting file from uploads folder to files one,
|
||||
// so this uri has to be customizable
|
||||
Uri srcWebDavUri = isChunkedFile ? client.getNewUploadsWebDavUri() : client.getNewFilesWebDavUri();
|
||||
Uri srcWebDavUri = moveChunkedFile ? client.getNewUploadsWebDavUri() : client.getNewFilesWebDavUri();
|
||||
|
||||
final MoveMethod move = new MoveMethod(
|
||||
HttpUrl.parse(srcWebDavUri + WebdavUtils.encodePath(mSrcRemotePath)),
|
||||
client.getNewFilesWebDavUri() + WebdavUtils.encodePath(mTargetRemotePath),
|
||||
mOverwrite);
|
||||
|
||||
if (isChunkedFile) {
|
||||
if (moveChunkedFile) {
|
||||
move.addRequestHeader(HttpConstants.OC_X_OC_MTIME_HEADER, mFileLastModifTimestamp);
|
||||
move.addRequestHeader(HttpConstants.OC_TOTAL_LENGTH_HEADER, String.valueOf(mFileLength));
|
||||
}
|
||||
|
@ -24,6 +24,8 @@
|
||||
|
||||
package com.owncloud.android.lib.resources.files;
|
||||
|
||||
import android.net.Uri;
|
||||
|
||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||
import com.owncloud.android.lib.common.http.HttpConstants;
|
||||
import com.owncloud.android.lib.common.http.HttpUtils;
|
||||
@ -46,6 +48,8 @@ public class RemoveRemoteFileOperation extends RemoteOperation {
|
||||
private static final String TAG = RemoveRemoteFileOperation.class.getSimpleName();
|
||||
private String mRemotePath;
|
||||
|
||||
protected boolean removeChunksFolder = false;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
@ -65,8 +69,10 @@ public class RemoveRemoteFileOperation extends RemoteOperation {
|
||||
RemoteOperationResult result;
|
||||
|
||||
try {
|
||||
Uri srcWebDavUri = removeChunksFolder ? client.getNewUploadsWebDavUri() : client.getNewFilesWebDavUri();
|
||||
|
||||
DeleteMethod deleteMethod = new DeleteMethod(
|
||||
HttpUtils.stringUrlToHttpUrl(client.getNewFilesWebDavUri() + WebdavUtils.encodePath(mRemotePath))
|
||||
HttpUtils.stringUrlToHttpUrl(srcWebDavUri + WebdavUtils.encodePath(mRemotePath))
|
||||
);
|
||||
|
||||
int status = client.executeHttpMethod(deleteMethod);
|
||||
|
@ -22,7 +22,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
package com.owncloud.android.lib.resources.files;
|
||||
package com.owncloud.android.lib.resources.files.chunks;
|
||||
|
||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||
import com.owncloud.android.lib.common.http.HttpUtils;
|
||||
@ -31,6 +31,8 @@ import com.owncloud.android.lib.common.network.ChunkFromFileRequestBody;
|
||||
import com.owncloud.android.lib.common.operations.OperationCancelledException;
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
import com.owncloud.android.lib.resources.files.FileUtils;
|
||||
import com.owncloud.android.lib.resources.files.UploadRemoteFileOperation;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.RandomAccessFile;
|
@ -22,7 +22,9 @@
|
||||
*
|
||||
*/
|
||||
|
||||
package com.owncloud.android.lib.resources.files;
|
||||
package com.owncloud.android.lib.resources.files.chunks;
|
||||
|
||||
import com.owncloud.android.lib.resources.files.CreateRemoteFolderOperation;
|
||||
|
||||
/**
|
||||
* Remote operation performing the creation of a new folder to save chunks during an upload to the ownCloud server.
|
||||
@ -38,6 +40,6 @@ public class CreateRemoteChunkFolderOperation extends CreateRemoteFolderOperatio
|
||||
*/
|
||||
public CreateRemoteChunkFolderOperation(String remotePath, boolean createFullPath) {
|
||||
super(remotePath, createFullPath);
|
||||
mFolderToSaveChunks = true;
|
||||
createChunksFolder = true;
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
/* ownCloud Android Library is available under MIT license
|
||||
* Copyright (C) 2018 ownCloud GmbH.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
||||
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.owncloud.android.lib.resources.files.chunks;
|
||||
|
||||
import com.owncloud.android.lib.resources.files.MoveRemoteFileOperation;
|
||||
|
||||
/**
|
||||
* Remote operation to move the file built from chunks after uploading it
|
||||
*
|
||||
* @author David González Verdugo
|
||||
*/
|
||||
public class MoveRemoteChunksFileOperation extends MoveRemoteFileOperation {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param srcRemotePath Remote path of the file/folder to move.
|
||||
* @param targetRemotePath Remove path desired for the file/folder after moving it.
|
||||
* @param overwrite
|
||||
*/
|
||||
public MoveRemoteChunksFileOperation(String srcRemotePath, String targetRemotePath, boolean overwrite,
|
||||
String fileLastModifTimestamp, long fileLength) {
|
||||
super(srcRemotePath, targetRemotePath, overwrite);
|
||||
moveChunkedFile = true;
|
||||
mFileLastModifTimestamp = fileLastModifTimestamp;
|
||||
mFileLength = fileLength;
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package com.owncloud.android.lib.resources.files.chunks;
|
||||
|
||||
import com.owncloud.android.lib.resources.files.RemoveRemoteFileOperation;
|
||||
|
||||
public class RemoveRemoteChunksFolderOperation extends RemoveRemoteFileOperation {
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param remotePath RemotePath of the remote file or folder to remove from the server
|
||||
*/
|
||||
public RemoveRemoteChunksFolderOperation(String remotePath) {
|
||||
super(remotePath);
|
||||
removeChunksFolder = true;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user