Commit b5416a46 authored by vince-bourgmayer's avatar vince-bourgmayer
Browse files

merge branch fix-e/apps/eDrive#23-nougat

parent 42a47542
Pipeline #3554 passed with stage
in 2 minutes and 4 seconds
...@@ -4,6 +4,8 @@ stages: ...@@ -4,6 +4,8 @@ stages:
- build - build
before_script: before_script:
- git submodule sync
- git submodule update --init --recursive
- export GRADLE_USER_HOME=$(pwd)/.gradle - export GRADLE_USER_HOME=$(pwd)/.gradle
- chmod +x ./gradlew - chmod +x ./gradlew
......
[submodule "nextcloud-android-lib"]
path = nextcloud-android-lib
url = ../nextcloud-android-lib.git
\ No newline at end of file
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
<set> <set>
<option value="$PROJECT_DIR$" /> <option value="$PROJECT_DIR$" />
<option value="$PROJECT_DIR$/app" /> <option value="$PROJECT_DIR$/app" />
<option value="$PROJECT_DIR$/nextcloud-android-lib" />
</set> </set>
</option> </option>
<option name="resolveModulePerSourceSet" value="false" /> <option name="resolveModulePerSourceSet" value="false" />
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
<component name="ProjectModuleManager"> <component name="ProjectModuleManager">
<modules> <modules>
<module fileurl="file://$PROJECT_DIR$/Drive.iml" filepath="$PROJECT_DIR$/Drive.iml" /> <module fileurl="file://$PROJECT_DIR$/Drive.iml" filepath="$PROJECT_DIR$/Drive.iml" />
<module fileurl="file://$PROJECT_DIR$/nextcloud-android-lib/NextcloudLib.iml" filepath="$PROJECT_DIR$/nextcloud-android-lib/NextcloudLib.iml" />
<module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" /> <module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
<module fileurl="file://$PROJECT_DIR$/eDrive.iml" filepath="$PROJECT_DIR$/eDrive.iml" /> <module fileurl="file://$PROJECT_DIR$/eDrive.iml" filepath="$PROJECT_DIR$/eDrive.iml" />
</modules> </modules>
......
...@@ -36,9 +36,7 @@ android { ...@@ -36,9 +36,7 @@ android {
unitTests.returnDefaultValues = true unitTests.returnDefaultValues = true
} }
} }
repositories {
maven { url "https://jitpack.io" }
}
dependencies { dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs') implementation fileTree(include: ['*.jar'], dir: 'libs')
...@@ -49,6 +47,6 @@ dependencies { ...@@ -49,6 +47,6 @@ dependencies {
androidTestImplementation 'com.android.support.test:rules:1.0.2' androidTestImplementation 'com.android.support.test:rules:1.0.2'
androidTestImplementation 'com.android.support:support-annotations:27.1.1' androidTestImplementation 'com.android.support:support-annotations:27.1.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
api 'com.github.nextcloud:android-library:1.1.0'
api 'com.android.support:support-annotations:27.1.1' api 'com.android.support:support-annotations:27.1.1'
api project(':NextcloudLib')
} }
...@@ -14,7 +14,7 @@ import android.util.Log; ...@@ -14,7 +14,7 @@ import android.util.Log;
import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperation;
import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.resources.files.CreateRemoteFolderOperation; import com.owncloud.android.lib.resources.files.CreateFolderRemoteOperation;
import java.io.File; import java.io.File;
...@@ -25,15 +25,15 @@ import io.eelo.drive.models.SyncedFolder; ...@@ -25,15 +25,15 @@ import io.eelo.drive.models.SyncedFolder;
* @author Vincent Bourgmayer * @author Vincent Bourgmayer
* Perform initial folder creation * Perform initial folder creation
*/ */
public class CreateInitialRemoteFolderOperation extends RemoteOperation { public class CreateInitialFolderRemoteOperation extends RemoteOperation {
private static final String TAG = CreateInitialRemoteFolderOperation.class.getSimpleName(); private static final String TAG = CreateInitialFolderRemoteOperation.class.getSimpleName();
private SyncedFolder mSyncedFolder; private SyncedFolder mSyncedFolder;
private String mRemotePath; private String mRemotePath;
private boolean mCreateFullPath;//should recreate parent path if not exist or not private boolean mCreateFullPath;//should recreate parent path if not exist or not
private final Context mContext; private final Context mContext;
public CreateInitialRemoteFolderOperation(SyncedFolder root, boolean createFullPath, Context context) { public CreateInitialFolderRemoteOperation(SyncedFolder root, boolean createFullPath, Context context) {
super(); super();
this.mSyncedFolder = root; this.mSyncedFolder = root;
this.mRemotePath = root.getRemoteFolder(); this.mRemotePath = root.getRemoteFolder();
...@@ -48,7 +48,7 @@ public class CreateInitialRemoteFolderOperation extends RemoteOperation { ...@@ -48,7 +48,7 @@ public class CreateInitialRemoteFolderOperation extends RemoteOperation {
Log.e(TAG, "Local folder doesn't exist, so create it"); Log.e(TAG, "Local folder doesn't exist, so create it");
folder.mkdirs(); folder.mkdirs();
} }
CreateRemoteFolderOperation createFolderOperation = new CreateRemoteFolderOperation(mRemotePath, mCreateFullPath); CreateFolderRemoteOperation createFolderOperation = new CreateFolderRemoteOperation(mRemotePath, mCreateFullPath);
RemoteOperationResult createOperationResult; RemoteOperationResult createOperationResult;
createOperationResult = createFolderOperation.execute(client, true); createOperationResult = createFolderOperation.execute(client, true);
......
...@@ -15,7 +15,7 @@ import com.owncloud.android.lib.common.OwnCloudClient; ...@@ -15,7 +15,7 @@ import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperation;
import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.resources.files.FileUtils; import com.owncloud.android.lib.resources.files.FileUtils;
import com.owncloud.android.lib.resources.files.RemoteFile; import com.owncloud.android.lib.resources.files.model.RemoteFile;
import java.io.File; import java.io.File;
...@@ -101,7 +101,7 @@ public class DownloadFileOperation extends RemoteOperation implements Comparable ...@@ -101,7 +101,7 @@ public class DownloadFileOperation extends RemoteOperation implements Comparable
return new RemoteOperationResult(RemoteOperationResult.ResultCode.ETAG_UNCHANGED ); return new RemoteOperationResult(RemoteOperationResult.ResultCode.ETAG_UNCHANGED );
} }
String tmpTargetPath = mContext.getExternalCacheDir()+ FileUtils.PATH_SEPARATOR+mSyncedState.getName(); String tmpTargetPath = mContext.getExternalCacheDir()+ FileUtils.PATH_SEPARATOR+mSyncedState.getName();
DownloadRemoteFileOperation downloadOperation = new DownloadRemoteFileOperation(mRFile.getRemotePath(), DownloadFileRemoteOperation downloadOperation = new DownloadFileRemoteOperation(mRFile.getRemotePath(),
tmpTargetPath); tmpTargetPath);
RemoteOperationResult downloadResult = downloadOperation.execute( ownCloudClient ); RemoteOperationResult downloadResult = downloadOperation.execute( ownCloudClient );
......
...@@ -25,7 +25,6 @@ ...@@ -25,7 +25,6 @@
package io.eelo.drive.operations; package io.eelo.drive.operations;
import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.network.OnDatatransferProgressListener;
import com.owncloud.android.lib.common.network.WebdavUtils; import com.owncloud.android.lib.common.network.WebdavUtils;
import com.owncloud.android.lib.common.operations.OperationCancelledException; import com.owncloud.android.lib.common.operations.OperationCancelledException;
import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperation;
...@@ -41,9 +40,6 @@ import java.io.File; ...@@ -41,9 +40,6 @@ import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.Date; import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
/** /**
...@@ -54,11 +50,9 @@ import java.util.concurrent.atomic.AtomicBoolean; ...@@ -54,11 +50,9 @@ import java.util.concurrent.atomic.AtomicBoolean;
* @author Vincent Bourgmayer * @author Vincent Bourgmayer
*/ */
class DownloadRemoteFileOperation extends RemoteOperation { class DownloadFileRemoteOperation extends RemoteOperation {
private static final String TAG = DownloadRemoteFileOperation.class.getSimpleName(); private static final String TAG = DownloadFileRemoteOperation.class.getSimpleName();
private final Set<OnDatatransferProgressListener> mDataTransferListeners = new HashSet<OnDatatransferProgressListener>();
private final AtomicBoolean mCancellationRequested = new AtomicBoolean(false); private final AtomicBoolean mCancellationRequested = new AtomicBoolean(false);
private long mModificationTimestamp = 0; private long mModificationTimestamp = 0;
private String mEtag = ""; private String mEtag = "";
...@@ -73,7 +67,7 @@ import java.util.concurrent.atomic.AtomicBoolean; ...@@ -73,7 +67,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
* @param remotePath Path of file on the server * @param remotePath Path of file on the server
* @param localFolderPath Path of file on the device * @param localFolderPath Path of file on the device
*/ */
public DownloadRemoteFileOperation(String remotePath, String localFolderPath) { public DownloadFileRemoteOperation(String remotePath, String localFolderPath) {
mRemotePath = remotePath; mRemotePath = remotePath;
mLocalFolderPath = localFolderPath; mLocalFolderPath = localFolderPath;
} }
...@@ -105,7 +99,6 @@ import java.util.concurrent.atomic.AtomicBoolean; ...@@ -105,7 +99,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
int status = -1; int status = -1;
boolean savedFile = false; boolean savedFile = false;
mGet = new GetMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath)); mGet = new GetMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath));
Iterator<OnDatatransferProgressListener> dataTransferListenerIterator = null;
FileOutputStream fos = null; FileOutputStream fos = null;
try { try {
...@@ -132,13 +125,7 @@ import java.util.concurrent.atomic.AtomicBoolean; ...@@ -132,13 +125,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
} }
fos.write(bytes, 0, readResult); fos.write(bytes, 0, readResult);
transferred += readResult; transferred += readResult;
synchronized (mDataTransferListeners) {
dataTransferListenerIterator = mDataTransferListeners.iterator();
while (dataTransferListenerIterator.hasNext()) {
dataTransferListenerIterator.next().onTransferProgress(readResult, transferred, totalToTransfer,
targetFile.getName());
}
}
} }
// Check if the file is completed // Check if the file is completed
// if transfer-encoding: chunked we cannot check if the file is complete // if transfer-encoding: chunked we cannot check if the file is complete
......
...@@ -14,8 +14,8 @@ import android.util.Log; ...@@ -14,8 +14,8 @@ import android.util.Log;
import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperation;
import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.resources.files.ReadRemoteFolderOperation; import com.owncloud.android.lib.resources.files.LightReadFolderRemoteOperation;
import com.owncloud.android.lib.resources.files.RemoteFile; import com.owncloud.android.lib.resources.files.model.RemoteFile;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -25,20 +25,22 @@ import java.util.ListIterator; ...@@ -25,20 +25,22 @@ import java.util.ListIterator;
import io.eelo.drive.database.DbHelper; import io.eelo.drive.database.DbHelper;
import io.eelo.drive.models.SyncedFolder; import io.eelo.drive.models.SyncedFolder;
import static org.apache.jackrabbit.webdav.DavConstants.DEPTH_1;
/** /**
* *
* @author Vincent Bourgmayer * @author Vincent Bourgmayer
* Created by Vincent on 04/05/2018. * Created by Vincent on 04/05/2018.
*/ */
public class ListRemoteFileOperation extends RemoteOperation { public class ListFileRemoteOperation extends RemoteOperation {
private final String TAG = ListRemoteFileOperation.class.getSimpleName(); private final String TAG = ListFileRemoteOperation.class.getSimpleName();
private final List<SyncedFolder> mSyncedFolders; private final List<SyncedFolder> mSyncedFolders;
private final Context mContext; private final Context mContext;
private final int initialFolderNumber; private final int initialFolderNumber;
public ListRemoteFileOperation(List<SyncedFolder> syncedFolders, Context context, int initialFolderNumber){ public ListFileRemoteOperation(List<SyncedFolder> syncedFolders, Context context, int initialFolderNumber){
Log.i(TAG, "Constructor of ListRemoteFileOperation"); Log.i(TAG, "Constructor of ListRemoteFileOperation");
this.mSyncedFolders = syncedFolders; this.mSyncedFolders = syncedFolders;
this.mContext = context; this.mContext = context;
...@@ -76,7 +78,7 @@ public class ListRemoteFileOperation extends RemoteOperation { ...@@ -76,7 +78,7 @@ public class ListRemoteFileOperation extends RemoteOperation {
} }
if(syncedFolder.getId() > 0){ if(syncedFolder.getId() > 0){
//Create ReadRemoteOperation //Create ReadRemoteOperation
ReadRemoteFolderOperation operation = new ReadRemoteFolderOperation(syncedFolder.getRemoteFolder()); LightReadFolderRemoteOperation operation = new LightReadFolderRemoteOperation(syncedFolder.getRemoteFolder(), DEPTH_1, false);
RemoteOperationResult result = operation.execute(ownCloudClient); RemoteOperationResult result = operation.execute(ownCloudClient);
if(result.isSuccess() ){ if(result.isSuccess() ){
...@@ -108,8 +110,13 @@ public class ListRemoteFileOperation extends RemoteOperation { ...@@ -108,8 +110,13 @@ public class ListRemoteFileOperation extends RemoteOperation {
atLeastOneDirAsChanged = true; atLeastOneDirAsChanged = true;
} }
}else if(dataSize == 1){ //Empty folder }else if(dataSize == 1){ //Empty folder
syncedFolder.setLastEtag( ( (RemoteFile) result.getData().get(0) ).getEtag() ).setToSync(true); RemoteFile directory = (RemoteFile) result.getData().get(0);
}//Last else correspond to error 404 at readRemoteFolderOperation (see below) if(!directory.getEtag().equals(syncedFolder.getLastEtag())) {
syncedFolder.setLastEtag(directory.getEtag()).setToSync(true);
atLeastOneDirAsChanged = true;
}
}//Last else correspond to error 404 at LightReadFolderRemoteOperation (see below)
}else{ //Result isn't a success }else{ //Result isn't a success
if(result.getHttpCode() == 404){ //File not found if(result.getHttpCode() == 404){ //File not found
atLeastOneDirAsChanged = true; atLeastOneDirAsChanged = true;
...@@ -128,7 +135,7 @@ public class ListRemoteFileOperation extends RemoteOperation { ...@@ -128,7 +135,7 @@ public class ListRemoteFileOperation extends RemoteOperation {
mSyncedFolderIterator.remove(); mSyncedFolderIterator.remove();
} }
} }
Log.w(TAG, "ReadRemoteFolderOperation failed : http " + result.getHttpCode() + ", " + result.getLogMessage()+" => Ignored"); Log.w(TAG, "LightReadFolderRemoteOperation failed : http " + result.getHttpCode() + ", " + result.getLogMessage()+" => Ignored");
} }
}else{ }else{
mSyncedFolderIterator.remove(); mSyncedFolderIterator.remove();
...@@ -146,4 +153,12 @@ public class ListRemoteFileOperation extends RemoteOperation { ...@@ -146,4 +153,12 @@ public class ListRemoteFileOperation extends RemoteOperation {
Log.v(TAG, "end of run()"); Log.v(TAG, "end of run()");
return finalResult; return finalResult;
} }
/**
*
* @return list of syncedFolder
*/
public List<SyncedFolder> getSyncedFolderList(){
return this.mSyncedFolders;
}
} }
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
package io.eelo.drive.operations; package io.eelo.drive.operations;
import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperation;
import com.owncloud.android.lib.resources.files.RemoveRemoteFileOperation; import com.owncloud.android.lib.resources.files.RemoveFileRemoteOperation;
import io.eelo.drive.models.SyncedFileState; import io.eelo.drive.models.SyncedFileState;
...@@ -19,7 +19,7 @@ import io.eelo.drive.models.SyncedFileState; ...@@ -19,7 +19,7 @@ import io.eelo.drive.models.SyncedFileState;
* Created by Vincent on 19/06/2018. * Created by Vincent on 19/06/2018.
* Class to be able to wrap concerned SyncedFileState in operation, so it can be retrieve at the end * Class to be able to wrap concerned SyncedFileState in operation, so it can be retrieve at the end
*/ */
public class RemoveFileOperation extends RemoveRemoteFileOperation implements ComparableOperation{ public class RemoveFileOperation extends RemoveFileRemoteOperation implements ComparableOperation{
private SyncedFileState mSyncedFileState; private SyncedFileState mSyncedFileState;
......
...@@ -8,22 +8,20 @@ ...@@ -8,22 +8,20 @@
package io.eelo.drive.operations; package io.eelo.drive.operations;
import android.app.NotificationManager;
import android.content.Context; import android.content.Context;
import android.util.Log; import android.util.Log;
import java.io.File;
import java.util.ArrayList;
import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.UserInfo;
import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperation;
import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.resources.files.CreateRemoteFolderOperation; import com.owncloud.android.lib.resources.files.CreateFolderRemoteOperation;
import com.owncloud.android.lib.resources.files.FileUtils; import com.owncloud.android.lib.resources.files.FileUtils;
import com.owncloud.android.lib.resources.files.ReadRemoteFileOperation; import com.owncloud.android.lib.resources.files.UploadFileRemoteOperation;
import com.owncloud.android.lib.resources.files.RemoteFile; import com.owncloud.android.lib.resources.users.GetRemoteUserInfoOperation;
import com.owncloud.android.lib.resources.files.UploadRemoteFileOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import io.eelo.drive.database.DbHelper; import io.eelo.drive.database.DbHelper;
import io.eelo.drive.models.SyncedFileState; import io.eelo.drive.models.SyncedFileState;
...@@ -38,7 +36,7 @@ public class UploadFileOperation extends RemoteOperation implements ComparableOp ...@@ -38,7 +36,7 @@ public class UploadFileOperation extends RemoteOperation implements ComparableOp
private int restartCounter =0; private int restartCounter =0;
private long previousLastModified; private long previousLastModified; //get to restore real value if all trials fails
private boolean checkEtag; private boolean checkEtag;
private String mTargetPath; private String mTargetPath;
...@@ -46,6 +44,8 @@ public class UploadFileOperation extends RemoteOperation implements ComparableOp ...@@ -46,6 +44,8 @@ public class UploadFileOperation extends RemoteOperation implements ComparableOp
private final Context mContext; private final Context mContext;
private SyncedFileState mSyncedState; private SyncedFileState mSyncedState;
private long availableQuota = -1;
@Override @Override
public RemoteOperation toRemoteOperation() { public RemoteOperation toRemoteOperation() {
return this; return this;
...@@ -62,23 +62,25 @@ public class UploadFileOperation extends RemoteOperation implements ComparableOp ...@@ -62,23 +62,25 @@ public class UploadFileOperation extends RemoteOperation implements ComparableOp
this.mFile = file; this.mFile = file;
this.mContext = context; this.mContext = context;
this.mTargetPath = targetPath; this.mTargetPath = targetPath;
String localPath = CommonUtils.getLocalPath( mFile );
//Try to load syncedFileState from DB //Try to load syncedFileState from DB
this.mSyncedState = DbHelper.loadSyncedFile( mContext, this.mSyncedState = DbHelper.loadSyncedFile( mContext,
CommonUtils.getLocalPath( mFile ), true ); localPath, true );
//Create a new instance and stored it if not stored in DB before //Create a new instance and stored it if not stored in DB before
if( this.mSyncedState == null ){ if( this.mSyncedState == null ){
//It's the first synchronisation of this file //It's the first synchronisation of this file
Log.d( TAG, "it's first synchronisation of:"+mFile.getName() ); Log.d( TAG, "it's first synchronisation of:"+mFile.getName() );
this.mSyncedState = new SyncedFileState(-1, mFile.getName(), this.mSyncedState = new SyncedFileState(-1, mFile.getName(),
CommonUtils.getLocalPath(mFile), localPath,
mTargetPath , mTargetPath ,
"", "",
mFile.lastModified(), 0,
syncedFolderId, syncedFolderIsMediaType); syncedFolderId, syncedFolderIsMediaType);
} }
Log.v(TAG, ""+mSyncedState.getLocalLastModified() );
this.previousLastModified = mSyncedState.getLocalLastModified(); this.previousLastModified = mSyncedState.getLocalLastModified();
} }
...@@ -114,7 +116,7 @@ public class UploadFileOperation extends RemoteOperation implements ComparableOp ...@@ -114,7 +116,7 @@ public class UploadFileOperation extends RemoteOperation implements ComparableOp
//as operation isn't executed immediatly, file might have been deleted since creation of operation //as operation isn't executed immediatly, file might have been deleted since creation of operation
if(mSyncedState == null || mTargetPath == null || !mFile.exists()){ if(mSyncedState == null || mTargetPath == null || !mFile.exists()){
Log.e(TAG, "run(client): no syncedFileState or target path, can't perform upload operation"); Log.e(TAG, "run(client): no syncedFileState or target path, can't perform upload operation");
return new RemoteOperationResult(RemoteOperationResult.ResultCode.FORBIDDEN); return new RemoteOperationResult(ResultCode.FORBIDDEN);
} }
if(mSyncedState.getId() == -1){ if(mSyncedState.getId() == -1){
this.mSyncedState.setId( DbHelper.manageSyncedFileStateDB(this.mSyncedState, "INSERT", mContext) ); this.mSyncedState.setId( DbHelper.manageSyncedFileStateDB(this.mSyncedState, "INSERT", mContext) );
...@@ -123,85 +125,72 @@ public class UploadFileOperation extends RemoteOperation implements ComparableOp ...@@ -123,85 +125,72 @@ public class UploadFileOperation extends RemoteOperation implements ComparableOp
//If an Etag is already Stored and LastModified from DB is the same as real file //If an Etag is already Stored and LastModified from DB is the same as real file
if (mSyncedState.isLastEtagStored() if (mSyncedState.isLastEtagStored()
&& mSyncedState.getLocalLastModified() == mFile.lastModified()) { && mSyncedState.getLocalLastModified() == mFile.lastModified()) {
return new RemoteOperationResult(RemoteOperationResult.ResultCode.SYNC_CONFLICT); Log.d(TAG, "mySyncedState last modified: "+mSyncedState.getLocalLastModified()+" <=> mFile last modified: "+mFile.lastModified() +": So return sync_conflict");
return new RemoteOperationResult(ResultCode.SYNC_CONFLICT);
} }
String timeStamp = ( (Long) ( mFile.lastModified() / 1000) ).toString() ; if(this.availableQuota == -1){
RemoteOperationResult checkQuotaResult = checkAvailableSpace(client);
if( checkQuotaResult.getCode() != ResultCode.OK ){
return new RemoteOperationResult(checkQuotaResult.getCode());
}
}
UploadFileRemoteOperation uploadOperation = buildUploadOperation();
//create UploadFileOperation
UploadRemoteFileOperation uploadRemoteFileOperation = new UploadRemoteFileOperation( mSyncedState.getLocalPath(),
( mTargetPath != null ) ? mTargetPath : mSyncedState.getRemotePath(),
CommonUtils.getMimeType( mFile ),
( !checkEtag || mSyncedState.getLastETAG().isEmpty() )? null : mSyncedState.getLastETAG(), //If not null, This can cause error 412; that means remote file has change
timeStamp );
// Execute UploadFileOperation // Execute UploadFileOperation
RemoteOperationResult uploadResult = uploadRemoteFileOperation.execute( client ); RemoteOperationResult uploadResult = uploadOperation.execute( client );
RemoteOperationResult.ResultCode mResultCode; ResultCode mResultCode;
boolean mustRestart = true; boolean mustRestart = true;
//if upload is a success //if upload is a success
if( uploadResult.isSuccess() ){ if( uploadResult.isSuccess() ){
// get new Etag of the file on the server Object data = uploadResult.getSingleData();
ReadRemoteFileOperation getEtagOp = new ReadRemoteFileOperation( mTargetPath ); if(data != null) {
RemoteOperationResult readRemoteOpResult = getEtagOp.execute( client ); mSyncedState.setLastETAG((String) data);
//if readRemoteFile is a success
if ( readRemoteOpResult.isSuccess() ) {
List<Object> datas = readRemoteOpResult.getData();
if(datas != null) {
//extract new Etag and update SyncedFileState;
RemoteFile rf = (RemoteFile) datas.get(0);
//If length differs then there is an issue during transfer
if( rf.getLength() != this.mFile.length() ){