Checking of local file when an upload retry is requested

This commit is contained in:
Juan Carlos González Cabrero 2016-02-24 10:30:04 +01:00
parent d2940f6214
commit a506014d58
5 changed files with 28 additions and 3 deletions

@ -1 +1 @@
Subproject commit b0ac6b3fc94aa52a43927fae7b548e9123acf1bb Subproject commit 6ff6f75ee20e1b28f84a3ca5213dccb5907a2bed

View file

@ -127,6 +127,7 @@
<string name="uploads_view_upload_status_failed_credentials_error">Credentials error</string> <string name="uploads_view_upload_status_failed_credentials_error">Credentials error</string>
<string name="uploads_view_upload_status_failed_folder_error">Folder error</string> <string name="uploads_view_upload_status_failed_folder_error">Folder error</string>
<string name="uploads_view_upload_status_failed_file_error">File error</string> <string name="uploads_view_upload_status_failed_file_error">File error</string>
<string name="uploads_view_upload_status_failed_localfile_error">Local file not found</string>
<string name="uploads_view_upload_status_failed_permission_error">Permission error</string> <string name="uploads_view_upload_status_failed_permission_error">Permission error</string>
<string name="uploads_view_upload_status_failed">Upload failed</string> <string name="uploads_view_upload_status_failed">Upload failed</string>
<string name="uploads_view_later_reason_waiting_for">Waiting for </string> <string name="uploads_view_later_reason_waiting_for">Waiting for </string>
@ -440,5 +441,6 @@
<string name="manage_space_error">Some files could not be deleted.</string> <string name="manage_space_error">Some files could not be deleted.</string>
<string name="permission_storage_access">Additional permissions required to upload &amp; download files.</string> <string name="permission_storage_access">Additional permissions required to upload &amp; download files.</string>
<string name="local_file_not_found_toast">The file was not found locally</string>
</resources> </resources>

View file

@ -33,7 +33,8 @@ public enum UploadResult {
FILE_ERROR(5), FILE_ERROR(5),
PRIVILEDGES_ERROR(6), PRIVILEDGES_ERROR(6),
CANCELLED(7), CANCELLED(7),
UNKNOWN(8); FILE_NOT_FOUND(8),
UNKNOWN(9);
private final int value; private final int value;
@ -63,6 +64,8 @@ public enum UploadResult {
case 7: case 7:
return CANCELLED; return CANCELLED;
case 8: case 8:
return FILE_NOT_FOUND;
case 9:
return UNKNOWN; return UNKNOWN;
} }
return null; return null;
@ -82,6 +85,8 @@ public enum UploadResult {
return CREDENTIAL_ERROR; return CREDENTIAL_ERROR;
case FILE_NOT_FOUND: case FILE_NOT_FOUND:
return FOLDER_ERROR; return FOLDER_ERROR;
case LOCAL_FILE_NOT_FOUND:
return FILE_NOT_FOUND;
case CONFLICT: case CONFLICT:
return CONFLICT_ERROR; return CONFLICT_ERROR;
case LOCAL_STORAGE_NOT_COPIED: case LOCAL_STORAGE_NOT_COPIED:

View file

@ -332,6 +332,13 @@ public class UploadFileOperation extends SyncOperation {
mUploadStarted.set(true); mUploadStarted.set(true);
RemoteOperationResult result = null; RemoteOperationResult result = null;
File temporalFile = null, originalFile = new File(mOriginalStoragePath), expectedFile = null; File temporalFile = null, originalFile = new File(mOriginalStoragePath), expectedFile = null;
// check if the file continues existing before schedule the operation
if (!originalFile.exists()) {
Log_OC.d(TAG, mOriginalStoragePath.toString() + " not exists anymore");
return new RemoteOperationResult(ResultCode.LOCAL_FILE_NOT_FOUND);
}
try { try {
/// check the existence of the parent folder for the file to upload /// check the existence of the parent folder for the file to upload
String remoteParentPath = new File(getRemotePath()).getParent(); String remoteParentPath = new File(getRemotePath()).getParent();

View file

@ -34,6 +34,7 @@ import android.widget.ImageButton;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast;
import com.owncloud.android.R; import com.owncloud.android.R;
import com.owncloud.android.authentication.AuthenticatorActivity; import com.owncloud.android.authentication.AuthenticatorActivity;
@ -304,6 +305,10 @@ public class ExpandableUploadListAdapter extends BaseExpandableListAdapter imple
status = mParentActivity.getString( status = mParentActivity.getString(
R.string.uploads_view_upload_status_failed_folder_error); R.string.uploads_view_upload_status_failed_folder_error);
break; break;
case FILE_NOT_FOUND:
status = mParentActivity.getString(
R.string.uploads_view_upload_status_failed_localfile_error);
break;
case FILE_ERROR: case FILE_ERROR:
status = mParentActivity.getString( status = mParentActivity.getString(
R.string.uploads_view_upload_status_failed_file_error); R.string.uploads_view_upload_status_failed_file_error);
@ -411,7 +416,13 @@ public class ExpandableUploadListAdapter extends BaseExpandableListAdapter imple
view.setOnClickListener(new OnClickListener() { view.setOnClickListener(new OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
mParentActivity.getFileOperationsHelper().retryUpload(upload); File file = new File(upload.getLocalPath());
if (file.exists())
mParentActivity.getFileOperationsHelper().retryUpload(upload);
else {
final String message = String.format(mParentActivity.getString(R.string.local_file_not_found_toast));
Toast.makeText(mParentActivity, message, Toast.LENGTH_SHORT).show();
}
} }
}); });
} }