mirror of
https://github.com/nextcloud/android.git
synced 2024-11-28 18:28:59 +03:00
Merge pull request #6880 from grote/upload-retries
Don't disable upload retries for uploads from DocumentsProvider
This commit is contained in:
commit
caabf7b5dc
3 changed files with 66 additions and 16 deletions
|
@ -167,6 +167,11 @@ public class FileUploader extends Service
|
||||||
|
|
||||||
public static final String KEY_LOCAL_BEHAVIOUR = "BEHAVIOUR";
|
public static final String KEY_LOCAL_BEHAVIOUR = "BEHAVIOUR";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set to true if the HTTP library should disable automatic retries of uploads.
|
||||||
|
*/
|
||||||
|
public static final String KEY_DISABLE_RETRIES = "DISABLE_RETRIES";
|
||||||
|
|
||||||
public static final int LOCAL_BEHAVIOUR_COPY = 0;
|
public static final int LOCAL_BEHAVIOUR_COPY = 0;
|
||||||
public static final int LOCAL_BEHAVIOUR_MOVE = 1;
|
public static final int LOCAL_BEHAVIOUR_MOVE = 1;
|
||||||
public static final int LOCAL_BEHAVIOUR_FORGET = 2;
|
public static final int LOCAL_BEHAVIOUR_FORGET = 2;
|
||||||
|
@ -407,6 +412,7 @@ public class FileUploader extends Service
|
||||||
int localAction = intent.getIntExtra(KEY_LOCAL_BEHAVIOUR, LOCAL_BEHAVIOUR_FORGET);
|
int localAction = intent.getIntExtra(KEY_LOCAL_BEHAVIOUR, LOCAL_BEHAVIOUR_FORGET);
|
||||||
boolean isCreateRemoteFolder = intent.getBooleanExtra(KEY_CREATE_REMOTE_FOLDER, false);
|
boolean isCreateRemoteFolder = intent.getBooleanExtra(KEY_CREATE_REMOTE_FOLDER, false);
|
||||||
int createdBy = intent.getIntExtra(KEY_CREATED_BY, UploadFileOperation.CREATED_BY_USER);
|
int createdBy = intent.getIntExtra(KEY_CREATED_BY, UploadFileOperation.CREATED_BY_USER);
|
||||||
|
boolean disableRetries = intent.getBooleanExtra(KEY_DISABLE_RETRIES, true);
|
||||||
try {
|
try {
|
||||||
for (OCFile file : files) {
|
for (OCFile file : files) {
|
||||||
startNewUpload(
|
startNewUpload(
|
||||||
|
@ -418,7 +424,8 @@ public class FileUploader extends Service
|
||||||
localAction,
|
localAction,
|
||||||
isCreateRemoteFolder,
|
isCreateRemoteFolder,
|
||||||
createdBy,
|
createdBy,
|
||||||
file
|
file,
|
||||||
|
disableRetries
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
|
@ -446,7 +453,8 @@ public class FileUploader extends Service
|
||||||
int localAction,
|
int localAction,
|
||||||
boolean isCreateRemoteFolder,
|
boolean isCreateRemoteFolder,
|
||||||
int createdBy,
|
int createdBy,
|
||||||
OCFile file
|
OCFile file,
|
||||||
|
boolean disableRetries
|
||||||
) {
|
) {
|
||||||
OCUpload ocUpload = new OCUpload(file, user.toPlatformAccount());
|
OCUpload ocUpload = new OCUpload(file, user.toPlatformAccount());
|
||||||
ocUpload.setFileSize(file.getFileLength());
|
ocUpload.setFileSize(file.getFileLength());
|
||||||
|
@ -469,7 +477,8 @@ public class FileUploader extends Service
|
||||||
localAction,
|
localAction,
|
||||||
this,
|
this,
|
||||||
onWifiOnly,
|
onWifiOnly,
|
||||||
whileChargingOnly
|
whileChargingOnly,
|
||||||
|
disableRetries
|
||||||
);
|
);
|
||||||
newUpload.setCreatedBy(createdBy);
|
newUpload.setCreatedBy(createdBy);
|
||||||
if (isCreateRemoteFolder) {
|
if (isCreateRemoteFolder) {
|
||||||
|
@ -517,7 +526,8 @@ public class FileUploader extends Service
|
||||||
upload.getLocalAction(),
|
upload.getLocalAction(),
|
||||||
this,
|
this,
|
||||||
onWifiOnly,
|
onWifiOnly,
|
||||||
whileChargingOnly
|
whileChargingOnly,
|
||||||
|
true
|
||||||
);
|
);
|
||||||
|
|
||||||
newUpload.addDataTransferProgressListener(this);
|
newUpload.addDataTransferProgressListener(this);
|
||||||
|
@ -957,7 +967,7 @@ public class FileUploader extends Service
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Upload and overwrite an already uploaded file
|
* Upload and overwrite an already uploaded file with disabled retries
|
||||||
*/
|
*/
|
||||||
public static void uploadUpdateFile(
|
public static void uploadUpdateFile(
|
||||||
Context context,
|
Context context,
|
||||||
|
@ -966,7 +976,21 @@ public class FileUploader extends Service
|
||||||
Integer behaviour,
|
Integer behaviour,
|
||||||
NameCollisionPolicy nameCollisionPolicy
|
NameCollisionPolicy nameCollisionPolicy
|
||||||
) {
|
) {
|
||||||
uploadUpdateFile(context, account, new OCFile[]{existingFile}, behaviour, nameCollisionPolicy);
|
uploadUpdateFile(context, account, new OCFile[]{existingFile}, behaviour, nameCollisionPolicy, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Upload and overwrite an already uploaded file
|
||||||
|
*/
|
||||||
|
public static void uploadUpdateFile(
|
||||||
|
Context context,
|
||||||
|
Account account,
|
||||||
|
OCFile existingFile,
|
||||||
|
Integer behaviour,
|
||||||
|
NameCollisionPolicy nameCollisionPolicy,
|
||||||
|
boolean disableRetries
|
||||||
|
) {
|
||||||
|
uploadUpdateFile(context, account, new OCFile[]{existingFile}, behaviour, nameCollisionPolicy, disableRetries);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -977,7 +1001,8 @@ public class FileUploader extends Service
|
||||||
Account account,
|
Account account,
|
||||||
OCFile[] existingFiles,
|
OCFile[] existingFiles,
|
||||||
Integer behaviour,
|
Integer behaviour,
|
||||||
NameCollisionPolicy nameCollisionPolicy
|
NameCollisionPolicy nameCollisionPolicy,
|
||||||
|
boolean disableRetries
|
||||||
) {
|
) {
|
||||||
Intent intent = new Intent(context, FileUploader.class);
|
Intent intent = new Intent(context, FileUploader.class);
|
||||||
|
|
||||||
|
@ -985,6 +1010,7 @@ public class FileUploader extends Service
|
||||||
intent.putExtra(FileUploader.KEY_FILE, existingFiles);
|
intent.putExtra(FileUploader.KEY_FILE, existingFiles);
|
||||||
intent.putExtra(FileUploader.KEY_LOCAL_BEHAVIOUR, behaviour);
|
intent.putExtra(FileUploader.KEY_LOCAL_BEHAVIOUR, behaviour);
|
||||||
intent.putExtra(FileUploader.KEY_NAME_COLLISION_POLICY, nameCollisionPolicy);
|
intent.putExtra(FileUploader.KEY_NAME_COLLISION_POLICY, nameCollisionPolicy);
|
||||||
|
intent.putExtra(FileUploader.KEY_DISABLE_RETRIES, disableRetries);
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
context.startForegroundService(intent);
|
context.startForegroundService(intent);
|
||||||
|
|
|
@ -121,6 +121,7 @@ public class UploadFileOperation extends SyncOperation {
|
||||||
private boolean mOnWifiOnly;
|
private boolean mOnWifiOnly;
|
||||||
private boolean mWhileChargingOnly;
|
private boolean mWhileChargingOnly;
|
||||||
private boolean mIgnoringPowerSaveMode;
|
private boolean mIgnoringPowerSaveMode;
|
||||||
|
private final boolean mDisableRetries;
|
||||||
|
|
||||||
private boolean mWasRenamed;
|
private boolean mWasRenamed;
|
||||||
private long mOCUploadId;
|
private long mOCUploadId;
|
||||||
|
@ -184,8 +185,23 @@ public class UploadFileOperation extends SyncOperation {
|
||||||
int localBehaviour,
|
int localBehaviour,
|
||||||
Context context,
|
Context context,
|
||||||
boolean onWifiOnly,
|
boolean onWifiOnly,
|
||||||
boolean whileChargingOnly
|
boolean whileChargingOnly) {
|
||||||
) {
|
this(uploadsStorageManager, connectivityService, powerManagementService, user, file, upload,
|
||||||
|
nameCollisionPolicy, localBehaviour, context, onWifiOnly, whileChargingOnly, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public UploadFileOperation(UploadsStorageManager uploadsStorageManager,
|
||||||
|
ConnectivityService connectivityService,
|
||||||
|
PowerManagementService powerManagementService,
|
||||||
|
User user,
|
||||||
|
OCFile file,
|
||||||
|
OCUpload upload,
|
||||||
|
FileUploader.NameCollisionPolicy nameCollisionPolicy,
|
||||||
|
int localBehaviour,
|
||||||
|
Context context,
|
||||||
|
boolean onWifiOnly,
|
||||||
|
boolean whileChargingOnly,
|
||||||
|
boolean disableRetries) {
|
||||||
if (upload == null) {
|
if (upload == null) {
|
||||||
throw new IllegalArgumentException("Illegal NULL file in UploadFileOperation creation");
|
throw new IllegalArgumentException("Illegal NULL file in UploadFileOperation creation");
|
||||||
}
|
}
|
||||||
|
@ -222,6 +238,7 @@ public class UploadFileOperation extends SyncOperation {
|
||||||
// Ignore power save mode only if user explicitly created this upload
|
// Ignore power save mode only if user explicitly created this upload
|
||||||
mIgnoringPowerSaveMode = mCreatedBy == CREATED_BY_USER;
|
mIgnoringPowerSaveMode = mCreatedBy == CREATED_BY_USER;
|
||||||
mFolderUnlockToken = upload.getFolderUnlockToken();
|
mFolderUnlockToken = upload.getFolderUnlockToken();
|
||||||
|
mDisableRetries = disableRetries;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isWifiRequired() {
|
public boolean isWifiRequired() {
|
||||||
|
@ -561,14 +578,18 @@ public class UploadFileOperation extends SyncOperation {
|
||||||
mFile.getEtagInConflict(),
|
mFile.getEtagInConflict(),
|
||||||
timeStamp,
|
timeStamp,
|
||||||
onWifiConnection,
|
onWifiConnection,
|
||||||
token);
|
token,
|
||||||
|
mDisableRetries
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
mUploadOperation = new UploadFileRemoteOperation(encryptedTempFile.getAbsolutePath(),
|
mUploadOperation = new UploadFileRemoteOperation(encryptedTempFile.getAbsolutePath(),
|
||||||
mFile.getParentRemotePath() + encryptedFileName,
|
mFile.getParentRemotePath() + encryptedFileName,
|
||||||
mFile.getMimeType(),
|
mFile.getMimeType(),
|
||||||
mFile.getEtagInConflict(),
|
mFile.getEtagInConflict(),
|
||||||
timeStamp,
|
timeStamp,
|
||||||
token);
|
token,
|
||||||
|
mDisableRetries
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (OnDatatransferProgressListener mDataTransferListener : mDataTransferListeners) {
|
for (OnDatatransferProgressListener mDataTransferListener : mDataTransferListeners) {
|
||||||
|
@ -796,13 +817,15 @@ public class UploadFileOperation extends SyncOperation {
|
||||||
mFile.getMimeType(),
|
mFile.getMimeType(),
|
||||||
mFile.getEtagInConflict(),
|
mFile.getEtagInConflict(),
|
||||||
timeStamp,
|
timeStamp,
|
||||||
onWifiConnection);
|
onWifiConnection,
|
||||||
|
mDisableRetries);
|
||||||
} else {
|
} else {
|
||||||
mUploadOperation = new UploadFileRemoteOperation(mFile.getStoragePath(),
|
mUploadOperation = new UploadFileRemoteOperation(mFile.getStoragePath(),
|
||||||
mFile.getRemotePath(),
|
mFile.getRemotePath(),
|
||||||
mFile.getMimeType(),
|
mFile.getMimeType(),
|
||||||
mFile.getEtagInConflict(),
|
mFile.getEtagInConflict(),
|
||||||
timeStamp);
|
timeStamp,
|
||||||
|
mDisableRetries);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (OnDatatransferProgressListener mDataTransferListener : mDataTransferListeners) {
|
for (OnDatatransferProgressListener mDataTransferListener : mDataTransferListeners) {
|
||||||
|
|
|
@ -249,8 +249,8 @@ public class DocumentsStorageProvider extends DocumentsProvider {
|
||||||
account,
|
account,
|
||||||
ocFile,
|
ocFile,
|
||||||
LOCAL_BEHAVIOUR_MOVE,
|
LOCAL_BEHAVIOUR_MOVE,
|
||||||
NameCollisionPolicy.OVERWRITE
|
NameCollisionPolicy.OVERWRITE,
|
||||||
);
|
false);
|
||||||
} else { // error, no upload needed
|
} else { // error, no upload needed
|
||||||
Log_OC.e(TAG, "File was closed with an error: " + ocFile.getFileName(), error);
|
Log_OC.e(TAG, "File was closed with an error: " + ocFile.getFileName(), error);
|
||||||
}
|
}
|
||||||
|
@ -537,7 +537,8 @@ public class DocumentsStorageProvider extends DocumentsProvider {
|
||||||
newFilePath,
|
newFilePath,
|
||||||
mimeType,
|
mimeType,
|
||||||
"",
|
"",
|
||||||
String.valueOf(System.currentTimeMillis() / 1000))
|
String.valueOf(System.currentTimeMillis() / 1000),
|
||||||
|
false)
|
||||||
.execute(client);
|
.execute(client);
|
||||||
|
|
||||||
if (!result.isSuccess()) {
|
if (!result.isSuccess()) {
|
||||||
|
|
Loading…
Reference in a new issue