mirror of
				https://github.com/owncloud/android-library.git
				synced 2025-10-28 17:07:49 +00:00 
			
		
		
		
	Showing decision dialog when moving file conflict.
Solving errors when copying, replace and keep both.
This commit is contained in:
		
							parent
							
								
									d81ca97f14
								
							
						
					
					
						commit
						5b64876e2c
					
				| @ -36,7 +36,7 @@ import java.net.URL | ||||
| class CopyMethod( | ||||
|     val url: URL, | ||||
|     private val destinationUrl: String, | ||||
|     private val forceOverride: Boolean = false | ||||
|     val forceOverride: Boolean = false | ||||
| ) : DavMethod(url) { | ||||
|     @Throws(Exception::class) | ||||
|     public override fun onDavExecute(davResource: DavOCResource): Int { | ||||
|  | ||||
| @ -36,7 +36,7 @@ import java.net.URL | ||||
| class MoveMethod( | ||||
|     url: URL, | ||||
|     private val destinationUrl: String, | ||||
|     private val forceOverride: Boolean = false | ||||
|     val forceOverride: Boolean = false | ||||
| ) : DavMethod(url) { | ||||
|     @Throws(Exception::class) | ||||
|     override fun onDavExecute(davResource: DavOCResource): Int { | ||||
|  | ||||
| @ -79,6 +79,7 @@ class CopyRemoteFileOperation( | ||||
|                 destinationUrl = (targetSpaceWebDavUrl ?: client.userFilesWebDavUri.toString()) + WebdavUtils.encodePath(targetRemotePath), | ||||
|                 forceOverride = forceOverride, | ||||
|             ).apply { | ||||
|                 addRequestHeaders(this) | ||||
|                 setReadTimeout(COPY_READ_TIMEOUT, TimeUnit.SECONDS) | ||||
|                 setConnectionTimeout(COPY_CONNECTION_TIMEOUT, TimeUnit.SECONDS) | ||||
|             } | ||||
| @ -111,6 +112,13 @@ class CopyRemoteFileOperation( | ||||
|         return result | ||||
|     } | ||||
| 
 | ||||
|     private fun addRequestHeaders(copyMethod: CopyMethod) { | ||||
|         //Adding this because the library has an error whit override | ||||
|         if (copyMethod.forceOverride) { | ||||
|             copyMethod.setRequestHeader(OVERWRITE, TRUE) | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     private fun isSuccess(status: Int) = status.isOneOf(HttpConstants.HTTP_CREATED, HttpConstants.HTTP_NO_CONTENT) | ||||
| 
 | ||||
|     private fun isPreconditionFailed(status: Int) = status == HttpConstants.HTTP_PRECONDITION_FAILED | ||||
| @ -118,5 +126,7 @@ class CopyRemoteFileOperation( | ||||
|     companion object { | ||||
|         private const val COPY_READ_TIMEOUT = 10L | ||||
|         private const val COPY_CONNECTION_TIMEOUT = 6L | ||||
|         private const val OVERWRITE = "overwrite" | ||||
|         private const val TRUE = "T" | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -46,6 +46,7 @@ import java.util.concurrent.TimeUnit | ||||
|  * @author David González Verdugo | ||||
|  * @author Abel García de Prada | ||||
|  * @author Juan Carlos Garrote Gascón | ||||
|  * @author Manuel Plazas Palacio | ||||
|  * | ||||
|  * @param sourceRemotePath  Remote path of the file/folder to copy. | ||||
|  * @param targetRemotePath  Remote path desired for the file/folder to copy it. | ||||
| @ -54,6 +55,7 @@ open class MoveRemoteFileOperation( | ||||
|     private val sourceRemotePath: String, | ||||
|     private val targetRemotePath: String, | ||||
|     private val spaceWebDavUrl: String? = null, | ||||
|     private val forceOverride: Boolean = false, | ||||
| ) : RemoteOperation<Unit>() { | ||||
| 
 | ||||
|     /** | ||||
| @ -80,6 +82,7 @@ open class MoveRemoteFileOperation( | ||||
|             val moveMethod = MoveMethod( | ||||
|                 url = URL((spaceWebDavUrl ?: srcWebDavUri.toString()) + WebdavUtils.encodePath(sourceRemotePath)), | ||||
|                 destinationUrl = (spaceWebDavUrl ?: client.userFilesWebDavUri.toString()) + WebdavUtils.encodePath(targetRemotePath), | ||||
|                 forceOverride = forceOverride, | ||||
|             ).apply { | ||||
|                 addRequestHeaders(this) | ||||
|                 setReadTimeout(MOVE_READ_TIMEOUT, TimeUnit.SECONDS) | ||||
| @ -92,6 +95,7 @@ open class MoveRemoteFileOperation( | ||||
|                 isSuccess(status) -> { | ||||
|                     result = RemoteOperationResult<Unit>(ResultCode.OK) | ||||
|                 } | ||||
| 
 | ||||
|                 isPreconditionFailed(status) -> { | ||||
|                     result = RemoteOperationResult<Unit>(ResultCode.INVALID_OVERWRITE) | ||||
|                     client.exhaustResponse(moveMethod.getResponseBodyAsStream()) | ||||
| @ -99,6 +103,7 @@ open class MoveRemoteFileOperation( | ||||
|                     /// for other errors that could be explicitly handled, check first: | ||||
|                     /// http://www.webdav.org/specs/rfc4918.html#rfc.section.9.9.4 | ||||
|                 } | ||||
| 
 | ||||
|                 else -> { | ||||
|                     result = RemoteOperationResult<Unit>(moveMethod) | ||||
|                     client.exhaustResponse(moveMethod.getResponseBodyAsStream()) | ||||
| @ -125,6 +130,10 @@ open class MoveRemoteFileOperation( | ||||
|      * In case new headers are needed, override this method | ||||
|      */ | ||||
|     open fun addRequestHeaders(moveMethod: MoveMethod) { | ||||
|         //Adding this because the library has an error whit override | ||||
|         if (moveMethod.forceOverride) { | ||||
|             moveMethod.setRequestHeader(OVERWRITE, TRUE) | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     private fun isSuccess(status: Int) = status.isOneOf(HttpConstants.HTTP_CREATED, HttpConstants.HTTP_NO_CONTENT) | ||||
| @ -134,5 +143,7 @@ open class MoveRemoteFileOperation( | ||||
|     companion object { | ||||
|         private const val MOVE_READ_TIMEOUT = 10L | ||||
|         private const val MOVE_CONNECTION_TIMEOUT = 6L | ||||
|         private const val OVERWRITE = "overwrite" | ||||
|         private const val TRUE = "T" | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -58,6 +58,7 @@ interface FileService : Service { | ||||
|         sourceRemotePath: String, | ||||
|         targetRemotePath: String, | ||||
|         spaceWebDavUrl: String?, | ||||
|         replace: Boolean, | ||||
|     ): RemoteOperationResult<Unit> | ||||
| 
 | ||||
|     fun readFile( | ||||
|  | ||||
| @ -90,11 +90,13 @@ class OCFileService(override val client: OwnCloudClient) : FileService { | ||||
|         sourceRemotePath: String, | ||||
|         targetRemotePath: String, | ||||
|         spaceWebDavUrl: String?, | ||||
|         replace: Boolean, | ||||
|     ): RemoteOperationResult<Unit> = | ||||
|         MoveRemoteFileOperation( | ||||
|             sourceRemotePath = sourceRemotePath, | ||||
|             targetRemotePath = targetRemotePath, | ||||
|             spaceWebDavUrl = spaceWebDavUrl, | ||||
|             forceOverride = replace, | ||||
|         ).execute(client) | ||||
| 
 | ||||
|     override fun readFile( | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user