Loading app/src/main/java/foundation/e/drive/models/SyncedFileState.java +8 −1 Original line number Diff line number Diff line Loading @@ -23,7 +23,6 @@ public class SyncedFileState implements Parcelable { public static final int DEVICE_SCANNABLE=2; public static final int ALL_SCANNABLE=3; protected SyncedFileState(){}; //@ToRemove. Test Only. It's to allow to make a mock SyncedFileState Class in test. private int id; private String name; //name of the file private String localPath; //Path on the device file system Loading Loading @@ -144,6 +143,14 @@ public class SyncedFileState implements Parcelable { return (this.lastETAG != null && !this.lastETAG.isEmpty() ); } /** * Determine in it has already been synchronized once. * @return true if contains data for both local (local last modified) & remote file (eTag) */ public boolean hasBeenSynchronizedOnce() { return (this.isLastEtagStored() && this.getLocalLastModified() > 0L); } /** * Get the syncedFolder _id * @return long Loading app/src/main/java/foundation/e/drive/services/ObserverService.java +54 −49 Original line number Diff line number Diff line Loading @@ -416,7 +416,7 @@ public class ObserverService extends Service implements OnRemoteOperationListene if ( mSyncedFolders.get(j).getRemoteFolder().equals( parentOfKnownPath ) ) { //We have found the parent folder final SyncedFolder parentFolder = mSyncedFolders.get(j); String fileName = CommonUtils.getFileNameFromPath(remoteFilePath); //get remote file's name final String fileName = CommonUtils.getFileNameFromPath(remoteFilePath); if (fileName != null) { int scannableValue = 0; Loading Loading @@ -462,17 +462,20 @@ public class ObserverService extends Service implements OnRemoteOperationListene //Loop through remaining file state for(int i = -1, size = syncedFileStates.size(); ++i < size; ){ SyncedFileState syncedFileState = syncedFileStates.get(i); final SyncedFileState syncedFileState = syncedFileStates.get(i); if ( !CommonUtils.isThisSyncAllowed(mAccount, syncedFileState.isMediaType() ) ){ Log.d(TAG, "Sync of current file: " + syncedFileState.getName() + " isn't allowed"); continue; } //Check that file has already been synced fully if ( syncedFileState.isLastEtagStored() && syncedFileState.getLocalLastModified() > 0L) { if (!syncedFileState.hasBeenSynchronizedOnce()) { continue; } //Get local file File file = new File( syncedFileStates.get(i).getLocalPath() ); final File file = new File( syncedFileStates.get(i).getLocalPath() ); //Try to remove local file boolean fileExists = file.exists(); Loading @@ -490,9 +493,10 @@ public class ObserverService extends Service implements OnRemoteOperationListene //if it succeed, remove syncedFileState in DB if (!fileExists) { //It means that file has been correctly deleted from device. So update DB. if (DbHelper.manageSyncedFileStateDB(syncedFileState, "DELETE", this) <= 0) if (DbHelper.manageSyncedFileStateDB(syncedFileState, "DELETE", this) <= 0) { Log.e(TAG, "SyncedFileState row hasn't been deleted from DB"); } else } } else { Log.w(TAG, "local file:" + file.getName() + " still exist and can't be remove"); } } Loading Loading @@ -546,10 +550,10 @@ public class ObserverService extends Service implements OnRemoteOperationListene if (CommonUtils.isSettingsSyncEnabled(mAccount)) generateAppListFile(); ListIterator<SyncedFolder> iterator = mSyncedFolders.listIterator() ; final ListIterator<SyncedFolder> iterator = mSyncedFolders.listIterator() ; //Loop through folders while(iterator.hasNext()) { SyncedFolder syncedFolder = iterator.next(); final SyncedFolder syncedFolder = iterator.next(); Log.d(TAG, "SyncedFolder :"+syncedFolder.getLibelle()+", "+syncedFolder.getLocalFolder()+", "+syncedFolder.getLastModified()+", "+syncedFolder.isScanLocal()+", "+syncedFolder.getId() ); //Check it's not a hidden file Loading Loading @@ -656,14 +660,15 @@ public class ObserverService extends Service implements OnRemoteOperationListene //Loop through local files for (int i =-1, localFilesSize = localFileList.size(); ++i < localFilesSize;){ File localFile = localFileList.get(i); String filePath = CommonUtils.getLocalPath( localFile ); final File localFile = localFileList.get(i); final String filePath = CommonUtils.getLocalPath( localFile ); boolean correspondant_found = false; Log.v(TAG, "Current file is "+filePath+", exist: "+localFile.exists()+", last modified: "+localFile.lastModified() ); ListIterator<SyncedFileState> syncedFileListIterator = syncedFileStates.listIterator(); final ListIterator<SyncedFileState> syncedFileListIterator = syncedFileStates.listIterator(); Log.d(TAG, "Loop through syncedFileStates "); while( syncedFileListIterator.hasNext() ) { final SyncedFileState syncedFileState = syncedFileListIterator.next(); Loading Loading @@ -703,7 +708,7 @@ public class ObserverService extends Service implements OnRemoteOperationListene } //create the syncedFile State SyncedFileState newSyncedFileState = new SyncedFileState(-1, localFile.getName(), filePath, syncedFolder.getRemoteFolder() + localFile.getName(), "", 0, syncedFolder.getId(), syncedFolder.isMediaType(),scannableValue); final SyncedFileState newSyncedFileState = new SyncedFileState(-1, localFile.getName(), filePath, syncedFolder.getRemoteFolder() + localFile.getName(), "", 0, syncedFolder.getId(), syncedFolder.isMediaType(),scannableValue); //Store it in DB int storedId = DbHelper.manageSyncedFileStateDB(newSyncedFileState, "INSERT", this); Loading @@ -728,21 +733,21 @@ public class ObserverService extends Service implements OnRemoteOperationListene */ private void handleLocalRemainingSyncedFileState(List<SyncedFileState> syncedFileStates){ Log.i(TAG, "handleLocalRemainingSyncedFileState(...)"); //Loop through remaining SyncedFileState for(SyncedFileState fileState : syncedFileStates){ if (fileState.isLastEtagStored() && fileState.getLocalLastModified() > 0L){ //try to get File File file = new File(fileState.getLocalPath()); Log.v(TAG, "File : "+file.getAbsolutePath()+","+file.exists()); if (!fileState.hasBeenSynchronizedOnce()) { continue; } final File file = new File(fileState.getLocalPath()); if (file.exists()){ Log.w(TAG, "The file still exist. There is a problem!"); Log.w(TAG, file.getAbsolutePath() + "The file still exist. There is a problem!"); } else { Log.i(TAG, "Add remote remove request for file "+fileState.getId()); Log.i(TAG, "Add remove SyncRequest for file " + file.getAbsolutePath()); this.syncRequests.put(fileState.getId(), new SyncRequest(fileState, SyncRequest.Type.REMOTE_DELETE)); } } } } /* end of methods related to device Scanning */ @Nullable Loading app/src/main/java/foundation/e/drive/utils/FileDiffUtils.java +0 −7 Original line number Diff line number Diff line Loading @@ -7,14 +7,9 @@ */ 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; /** Loading @@ -27,12 +22,10 @@ public class FileDiffUtils { public enum Action { Upload, Download, Remove, skip, updateDB } /** * Define what to do of RemoteFile for which we know the Database equivalent * @param remoteFile RemoteFile Loading Loading
app/src/main/java/foundation/e/drive/models/SyncedFileState.java +8 −1 Original line number Diff line number Diff line Loading @@ -23,7 +23,6 @@ public class SyncedFileState implements Parcelable { public static final int DEVICE_SCANNABLE=2; public static final int ALL_SCANNABLE=3; protected SyncedFileState(){}; //@ToRemove. Test Only. It's to allow to make a mock SyncedFileState Class in test. private int id; private String name; //name of the file private String localPath; //Path on the device file system Loading Loading @@ -144,6 +143,14 @@ public class SyncedFileState implements Parcelable { return (this.lastETAG != null && !this.lastETAG.isEmpty() ); } /** * Determine in it has already been synchronized once. * @return true if contains data for both local (local last modified) & remote file (eTag) */ public boolean hasBeenSynchronizedOnce() { return (this.isLastEtagStored() && this.getLocalLastModified() > 0L); } /** * Get the syncedFolder _id * @return long Loading
app/src/main/java/foundation/e/drive/services/ObserverService.java +54 −49 Original line number Diff line number Diff line Loading @@ -416,7 +416,7 @@ public class ObserverService extends Service implements OnRemoteOperationListene if ( mSyncedFolders.get(j).getRemoteFolder().equals( parentOfKnownPath ) ) { //We have found the parent folder final SyncedFolder parentFolder = mSyncedFolders.get(j); String fileName = CommonUtils.getFileNameFromPath(remoteFilePath); //get remote file's name final String fileName = CommonUtils.getFileNameFromPath(remoteFilePath); if (fileName != null) { int scannableValue = 0; Loading Loading @@ -462,17 +462,20 @@ public class ObserverService extends Service implements OnRemoteOperationListene //Loop through remaining file state for(int i = -1, size = syncedFileStates.size(); ++i < size; ){ SyncedFileState syncedFileState = syncedFileStates.get(i); final SyncedFileState syncedFileState = syncedFileStates.get(i); if ( !CommonUtils.isThisSyncAllowed(mAccount, syncedFileState.isMediaType() ) ){ Log.d(TAG, "Sync of current file: " + syncedFileState.getName() + " isn't allowed"); continue; } //Check that file has already been synced fully if ( syncedFileState.isLastEtagStored() && syncedFileState.getLocalLastModified() > 0L) { if (!syncedFileState.hasBeenSynchronizedOnce()) { continue; } //Get local file File file = new File( syncedFileStates.get(i).getLocalPath() ); final File file = new File( syncedFileStates.get(i).getLocalPath() ); //Try to remove local file boolean fileExists = file.exists(); Loading @@ -490,9 +493,10 @@ public class ObserverService extends Service implements OnRemoteOperationListene //if it succeed, remove syncedFileState in DB if (!fileExists) { //It means that file has been correctly deleted from device. So update DB. if (DbHelper.manageSyncedFileStateDB(syncedFileState, "DELETE", this) <= 0) if (DbHelper.manageSyncedFileStateDB(syncedFileState, "DELETE", this) <= 0) { Log.e(TAG, "SyncedFileState row hasn't been deleted from DB"); } else } } else { Log.w(TAG, "local file:" + file.getName() + " still exist and can't be remove"); } } Loading Loading @@ -546,10 +550,10 @@ public class ObserverService extends Service implements OnRemoteOperationListene if (CommonUtils.isSettingsSyncEnabled(mAccount)) generateAppListFile(); ListIterator<SyncedFolder> iterator = mSyncedFolders.listIterator() ; final ListIterator<SyncedFolder> iterator = mSyncedFolders.listIterator() ; //Loop through folders while(iterator.hasNext()) { SyncedFolder syncedFolder = iterator.next(); final SyncedFolder syncedFolder = iterator.next(); Log.d(TAG, "SyncedFolder :"+syncedFolder.getLibelle()+", "+syncedFolder.getLocalFolder()+", "+syncedFolder.getLastModified()+", "+syncedFolder.isScanLocal()+", "+syncedFolder.getId() ); //Check it's not a hidden file Loading Loading @@ -656,14 +660,15 @@ public class ObserverService extends Service implements OnRemoteOperationListene //Loop through local files for (int i =-1, localFilesSize = localFileList.size(); ++i < localFilesSize;){ File localFile = localFileList.get(i); String filePath = CommonUtils.getLocalPath( localFile ); final File localFile = localFileList.get(i); final String filePath = CommonUtils.getLocalPath( localFile ); boolean correspondant_found = false; Log.v(TAG, "Current file is "+filePath+", exist: "+localFile.exists()+", last modified: "+localFile.lastModified() ); ListIterator<SyncedFileState> syncedFileListIterator = syncedFileStates.listIterator(); final ListIterator<SyncedFileState> syncedFileListIterator = syncedFileStates.listIterator(); Log.d(TAG, "Loop through syncedFileStates "); while( syncedFileListIterator.hasNext() ) { final SyncedFileState syncedFileState = syncedFileListIterator.next(); Loading Loading @@ -703,7 +708,7 @@ public class ObserverService extends Service implements OnRemoteOperationListene } //create the syncedFile State SyncedFileState newSyncedFileState = new SyncedFileState(-1, localFile.getName(), filePath, syncedFolder.getRemoteFolder() + localFile.getName(), "", 0, syncedFolder.getId(), syncedFolder.isMediaType(),scannableValue); final SyncedFileState newSyncedFileState = new SyncedFileState(-1, localFile.getName(), filePath, syncedFolder.getRemoteFolder() + localFile.getName(), "", 0, syncedFolder.getId(), syncedFolder.isMediaType(),scannableValue); //Store it in DB int storedId = DbHelper.manageSyncedFileStateDB(newSyncedFileState, "INSERT", this); Loading @@ -728,21 +733,21 @@ public class ObserverService extends Service implements OnRemoteOperationListene */ private void handleLocalRemainingSyncedFileState(List<SyncedFileState> syncedFileStates){ Log.i(TAG, "handleLocalRemainingSyncedFileState(...)"); //Loop through remaining SyncedFileState for(SyncedFileState fileState : syncedFileStates){ if (fileState.isLastEtagStored() && fileState.getLocalLastModified() > 0L){ //try to get File File file = new File(fileState.getLocalPath()); Log.v(TAG, "File : "+file.getAbsolutePath()+","+file.exists()); if (!fileState.hasBeenSynchronizedOnce()) { continue; } final File file = new File(fileState.getLocalPath()); if (file.exists()){ Log.w(TAG, "The file still exist. There is a problem!"); Log.w(TAG, file.getAbsolutePath() + "The file still exist. There is a problem!"); } else { Log.i(TAG, "Add remote remove request for file "+fileState.getId()); Log.i(TAG, "Add remove SyncRequest for file " + file.getAbsolutePath()); this.syncRequests.put(fileState.getId(), new SyncRequest(fileState, SyncRequest.Type.REMOTE_DELETE)); } } } } /* end of methods related to device Scanning */ @Nullable Loading
app/src/main/java/foundation/e/drive/utils/FileDiffUtils.java +0 −7 Original line number Diff line number Diff line Loading @@ -7,14 +7,9 @@ */ 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; /** Loading @@ -27,12 +22,10 @@ public class FileDiffUtils { public enum Action { Upload, Download, Remove, skip, updateDB } /** * Define what to do of RemoteFile for which we know the Database equivalent * @param remoteFile RemoteFile Loading