mirror of
https://github.com/nextcloud/android.git
synced 2024-11-28 18:28:59 +03:00
Merge pull request #7011 from dassio/skip_upload
add skip option in case of name collision
This commit is contained in:
commit
61aaba5b33
4 changed files with 118 additions and 7 deletions
|
@ -32,6 +32,7 @@ import com.owncloud.android.AbstractOnServerIT
|
||||||
import com.owncloud.android.datamodel.OCFile
|
import com.owncloud.android.datamodel.OCFile
|
||||||
import com.owncloud.android.datamodel.UploadsStorageManager
|
import com.owncloud.android.datamodel.UploadsStorageManager
|
||||||
import com.owncloud.android.db.OCUpload
|
import com.owncloud.android.db.OCUpload
|
||||||
|
import com.owncloud.android.lib.common.operations.OperationCancelledException
|
||||||
import com.owncloud.android.lib.resources.files.ReadFileRemoteOperation
|
import com.owncloud.android.lib.resources.files.ReadFileRemoteOperation
|
||||||
import com.owncloud.android.lib.resources.files.model.RemoteFile
|
import com.owncloud.android.lib.resources.files.model.RemoteFile
|
||||||
import com.owncloud.android.operations.UploadFileOperation
|
import com.owncloud.android.operations.UploadFileOperation
|
||||||
|
@ -397,4 +398,109 @@ class FileUploaderIT : AbstractOnServerIT() {
|
||||||
|
|
||||||
assertEquals(file.length(), (result2.data[0] as RemoteFile).length)
|
assertEquals(file.length(), (result2.data[0] as RemoteFile).length)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* uploads a file with "skip if exists" option set, so do nothing if file exists
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
fun testCancelServer() {
|
||||||
|
val file = getDummyFile("/chunkedFile.txt")
|
||||||
|
val ocUpload = OCUpload(file.absolutePath, "/testFile.txt", account.name)
|
||||||
|
|
||||||
|
assertTrue(
|
||||||
|
UploadFileOperation(
|
||||||
|
uploadsStorageManager,
|
||||||
|
connectivityServiceMock,
|
||||||
|
powerManagementServiceMock,
|
||||||
|
user,
|
||||||
|
null,
|
||||||
|
ocUpload,
|
||||||
|
FileUploader.NameCollisionPolicy.CANCEL,
|
||||||
|
FileUploader.LOCAL_BEHAVIOUR_COPY,
|
||||||
|
targetContext,
|
||||||
|
false,
|
||||||
|
false
|
||||||
|
)
|
||||||
|
.setRemoteFolderToBeCreated()
|
||||||
|
.execute(client, storageManager)
|
||||||
|
.isSuccess
|
||||||
|
)
|
||||||
|
|
||||||
|
val result = ReadFileRemoteOperation("/testFile.txt").execute(client)
|
||||||
|
assertTrue(result.isSuccess)
|
||||||
|
|
||||||
|
assertEquals(file.length(), (result.data[0] as RemoteFile).length)
|
||||||
|
|
||||||
|
val ocUpload2 = OCUpload(getDummyFile("/empty.txt").absolutePath, "/testFile.txt", account.name)
|
||||||
|
|
||||||
|
val uploadResult = UploadFileOperation(
|
||||||
|
uploadsStorageManager,
|
||||||
|
connectivityServiceMock,
|
||||||
|
powerManagementServiceMock,
|
||||||
|
user,
|
||||||
|
null,
|
||||||
|
ocUpload2,
|
||||||
|
FileUploader.NameCollisionPolicy.CANCEL,
|
||||||
|
FileUploader.LOCAL_BEHAVIOUR_COPY,
|
||||||
|
targetContext,
|
||||||
|
false,
|
||||||
|
false
|
||||||
|
)
|
||||||
|
.execute(client, storageManager)
|
||||||
|
|
||||||
|
assertFalse(uploadResult.isSuccess)
|
||||||
|
assertTrue(uploadResult.exception is OperationCancelledException)
|
||||||
|
|
||||||
|
val result2 = ReadFileRemoteOperation("/testFile.txt").execute(client)
|
||||||
|
assertTrue(result2.isSuccess)
|
||||||
|
|
||||||
|
assertEquals(file.length(), (result2.data[0] as RemoteFile).length)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* uploads a file with "skip if exists" option set, so do nothing if file exists
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
fun testKeepCancelStatic() {
|
||||||
|
val file = getDummyFile("/chunkedFile.txt")
|
||||||
|
|
||||||
|
FileUploader.uploadNewFile(
|
||||||
|
targetContext,
|
||||||
|
account,
|
||||||
|
file.absolutePath,
|
||||||
|
"/testFile.txt",
|
||||||
|
FileUploader.LOCAL_BEHAVIOUR_COPY,
|
||||||
|
null,
|
||||||
|
true,
|
||||||
|
UploadFileOperation.CREATED_BY_USER,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
FileUploader.NameCollisionPolicy.DEFAULT
|
||||||
|
)
|
||||||
|
|
||||||
|
longSleep()
|
||||||
|
|
||||||
|
val result = ReadFileRemoteOperation("/testFile.txt").execute(client)
|
||||||
|
assertTrue(result.isSuccess)
|
||||||
|
|
||||||
|
assertEquals(file.length(), (result.data[0] as RemoteFile).length)
|
||||||
|
|
||||||
|
val ocFile2 = OCFile("/testFile.txt")
|
||||||
|
ocFile2.setStoragePath(getDummyFile("/empty.txt").absolutePath)
|
||||||
|
|
||||||
|
FileUploader.uploadUpdateFile(
|
||||||
|
targetContext,
|
||||||
|
account,
|
||||||
|
ocFile2,
|
||||||
|
FileUploader.LOCAL_BEHAVIOUR_COPY,
|
||||||
|
FileUploader.NameCollisionPolicy.CANCEL
|
||||||
|
)
|
||||||
|
|
||||||
|
shortSleep()
|
||||||
|
|
||||||
|
val result2 = ReadFileRemoteOperation("/testFile.txt").execute(client)
|
||||||
|
assertTrue(result2.isSuccess)
|
||||||
|
|
||||||
|
assertEquals(file.length(), (result2.data[0] as RemoteFile).length)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,6 @@ import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.graphics.Typeface;
|
import android.graphics.Typeface;
|
||||||
import android.os.Build;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.text.style.StyleSpan;
|
import android.text.style.StyleSpan;
|
||||||
|
@ -113,11 +112,11 @@ public class SyncedFolderPreferencesDialogFragment extends DialogFragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAttach(Activity activity) {
|
public void onAttach(@NonNull Activity activity) {
|
||||||
super.onAttach(activity);
|
super.onAttach(activity);
|
||||||
if (!(activity instanceof OnSyncedFolderPreferenceListener)) {
|
if (!(activity instanceof OnSyncedFolderPreferenceListener)) {
|
||||||
throw new IllegalArgumentException("The host activity must implement "
|
throw new IllegalArgumentException("The host activity must implement "
|
||||||
+ OnSyncedFolderPreferenceListener.class.getCanonicalName());
|
+ OnSyncedFolderPreferenceListener.class.getCanonicalName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -584,7 +583,7 @@ public class SyncedFolderPreferencesDialogFragment extends DialogFragment {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get index for name collision selection dialog.
|
* Get index for name collision selection dialog.
|
||||||
* @return 0 if ASK_USER, 1 if OVERWRITE, 2 if RENAME. Otherwise: 0
|
* @return 0 if ASK_USER, 1 if OVERWRITE, 2 if RENAME, 3 if SKIP, Otherwise: 0
|
||||||
*/
|
*/
|
||||||
static private Integer getSelectionIndexForNameCollisionPolicy(FileUploader.NameCollisionPolicy nameCollisionPolicy) {
|
static private Integer getSelectionIndexForNameCollisionPolicy(FileUploader.NameCollisionPolicy nameCollisionPolicy) {
|
||||||
switch (nameCollisionPolicy) {
|
switch (nameCollisionPolicy) {
|
||||||
|
@ -592,6 +591,8 @@ public class SyncedFolderPreferencesDialogFragment extends DialogFragment {
|
||||||
return 1;
|
return 1;
|
||||||
case RENAME:
|
case RENAME:
|
||||||
return 2;
|
return 2;
|
||||||
|
case CANCEL:
|
||||||
|
return 3;
|
||||||
case ASK_USER:
|
case ASK_USER:
|
||||||
default:
|
default:
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -599,9 +600,9 @@ public class SyncedFolderPreferencesDialogFragment extends DialogFragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get index for name collision selection dialog.
|
* Get index for name collision selection dialog. Inverse of getSelectionIndexForNameCollisionPolicy.
|
||||||
* Inverse of getSelectionIndexForNameCollisionPolicy.
|
*
|
||||||
* @return ASK_USER if 0, OVERWRITE if 1, RENAME if 2. Otherwise: ASK_USEr
|
* @return ASK_USER if 0, OVERWRITE if 1, RENAME if 2, SKIP if 3. Otherwise: ASK_USER
|
||||||
*/
|
*/
|
||||||
static private FileUploader.NameCollisionPolicy getNameCollisionPolicyForSelectionIndex(int index) {
|
static private FileUploader.NameCollisionPolicy getNameCollisionPolicyForSelectionIndex(int index) {
|
||||||
switch (index) {
|
switch (index) {
|
||||||
|
@ -609,6 +610,8 @@ public class SyncedFolderPreferencesDialogFragment extends DialogFragment {
|
||||||
return FileUploader.NameCollisionPolicy.OVERWRITE;
|
return FileUploader.NameCollisionPolicy.OVERWRITE;
|
||||||
case 2:
|
case 2:
|
||||||
return FileUploader.NameCollisionPolicy.RENAME;
|
return FileUploader.NameCollisionPolicy.RENAME;
|
||||||
|
case 3:
|
||||||
|
return FileUploader.NameCollisionPolicy.CANCEL;
|
||||||
case 0:
|
case 0:
|
||||||
default:
|
default:
|
||||||
return FileUploader.NameCollisionPolicy.ASK_USER;
|
return FileUploader.NameCollisionPolicy.ASK_USER;
|
||||||
|
|
|
@ -16,5 +16,6 @@
|
||||||
<item>@string/pref_instant_name_collision_policy_entries_always_ask</item>
|
<item>@string/pref_instant_name_collision_policy_entries_always_ask</item>
|
||||||
<item>@string/pref_instant_name_collision_policy_entries_overwrite</item>
|
<item>@string/pref_instant_name_collision_policy_entries_overwrite</item>
|
||||||
<item>@string/pref_instant_name_collision_policy_entries_rename</item>
|
<item>@string/pref_instant_name_collision_policy_entries_rename</item>
|
||||||
|
<item>@string/pref_instant_name_collision_policy_entries_cancel</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
@ -459,6 +459,7 @@
|
||||||
<string name="pref_instant_name_collision_policy_entries_always_ask">Ask me every time</string>
|
<string name="pref_instant_name_collision_policy_entries_always_ask">Ask me every time</string>
|
||||||
<string name="pref_instant_name_collision_policy_entries_rename">Rename new version</string>
|
<string name="pref_instant_name_collision_policy_entries_rename">Rename new version</string>
|
||||||
<string name="pref_instant_name_collision_policy_entries_overwrite">Overwrite remote version</string>
|
<string name="pref_instant_name_collision_policy_entries_overwrite">Overwrite remote version</string>
|
||||||
|
<string name="pref_instant_name_collision_policy_entries_cancel">Skip uploading</string>
|
||||||
|
|
||||||
<string name="share_dialog_title">Sharing</string>
|
<string name="share_dialog_title">Sharing</string>
|
||||||
<string name="share_file">Share %1$s</string>
|
<string name="share_file">Share %1$s</string>
|
||||||
|
|
Loading…
Reference in a new issue