Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f01b25e4 authored by Vincent Bourgmayer's avatar Vincent Bourgmayer
Browse files

extract code to compare local file & Database into a dedicated method of FileDiffUtils

parent 10da3b6e
Loading
Loading
Loading
Loading
Loading
+5 −11
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ import foundation.e.drive.receivers.DebugCmdReceiver;
import foundation.e.drive.utils.AppConstants;
import foundation.e.drive.utils.CommonUtils;
import foundation.e.drive.utils.DavClientProvider;
import foundation.e.drive.utils.FileDiffUtils;
import foundation.e.drive.utils.FileDiffUtils.Action;
import foundation.e.drive.utils.ServiceExceptionHandler;
import foundation.e.drive.utils.SynchronizationServiceConnection;
@@ -651,7 +652,6 @@ public class ObserverService extends Service implements OnRemoteOperationListene
    private void handleLocalFiles(List<File> localFileList, List<SyncedFileState> syncedFileStates ){
        Log.i(TAG, "handleLocalFiles()");
        Log.d(TAG, "Loop through local file list");
        Log.v(TAG, "format: filePath, exist, lastModified) :");

        //Loop through local files
        for (int i =-1, localFilesSize = localFileList.size(); ++i < localFilesSize;){
@@ -660,14 +660,12 @@ public class ObserverService extends Service implements OnRemoteOperationListene
            String filePath = CommonUtils.getLocalPath( localFile );
            boolean correspondant_found = false;

            Log.v(TAG, "Current file is "+filePath+", "+localFile.exists()+", "+localFile.lastModified() );
            Log.v(TAG, "Current file is "+filePath+", exist: "+localFile.exists()+", last modified: "+localFile.lastModified() );

            ListIterator<SyncedFileState> syncedFileListIterator = syncedFileStates.listIterator();
            Log.d(TAG, "Loop through syncedFileStates ");
            Log.v(TAG, "format: (Path, Id, last Modified)");

            while( syncedFileListIterator.hasNext() ) {
                SyncedFileState syncedFileState = syncedFileListIterator.next();
                final SyncedFileState syncedFileState = syncedFileListIterator.next();

                //Ignore hidden media file store in DB
                if (syncedFileState.isMediaType() && syncedFileState.getName().startsWith(".")){
@@ -681,19 +679,15 @@ public class ObserverService extends Service implements OnRemoteOperationListene
                if ( syncedFileState.getLocalPath().equals( filePath ) ){
                    correspondant_found = true;

                    //If no etag is stored in sfs, the file hasn't been sync up to server. then do upload
                    if ( syncedFileState.getLocalLastModified() < localFile.lastModified() || !syncedFileState.isLastEtagStored()){
                        Log.i(TAG, "Add upload request for file "+syncedFileState.getId());
                    if (FileDiffUtils.getActionForFileDiff(localFile, syncedFileState) == Action.Upload) {
                        this.syncRequests.put(syncedFileState.getId(), new SyncRequest(syncedFileState, SyncRequest.Type.UPLOAD));
                    }
                    // No need to reloop on it.
                    syncedFileListIterator.remove();
                    break;
                }
            }
            if ( correspondant_found ) continue;

            //if no correspondance, then it is a new file
            Log.v(TAG, "this is a new file to sync");

            //Extract parent path from knownPath
+18 −0
Original line number Diff line number Diff line
@@ -7,10 +7,13 @@
 */
package foundation.e.drive.utils;

import android.util.Log;

import com.owncloud.android.lib.resources.files.model.RemoteFile;

import java.io.File;

import foundation.e.drive.models.SyncRequest;
import foundation.e.drive.models.SyncedFileState;

/**
@@ -47,6 +50,21 @@ public class FileDiffUtils {
        }
    }


    /**
     * Define what to do of local file for which we know the Database equivalent
     * @param localFile File instance representing a file on the device
     * @param fileState SyncedFileState instance. Containing data from Database
     * @return Action from Enum
     */
    public static Action getActionForFileDiff(File localFile, SyncedFileState fileState) {
        //If no etag is stored in sfs, the file hasn't been sync up to server. then do upload
        if ( fileState.getLocalLastModified() < localFile.lastModified() || !fileState.isLastEtagStored()) {
            return Action.Upload;
        }
        return Action.skip;
    }

    /**
     * Compare RemoteFile's eTag with the one stored in Database
     * @param file RemoteFile