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

Commit 59698f08 authored by vince-bourgmayer's avatar vince-bourgmayer
Browse files

fix for when server lack of free space

parent 57c1b65e
Loading
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -237,4 +237,22 @@ public final class DbHelper extends SQLiteOpenHelper {
        dao.close();
        return result+deleteSyncedFolder(id, context);
    }

    /**
     * Set the lastModified value of SyncedFolder to 1.
     * The goal is to force to rescan it next time.
     * @param syncedFolderId syncedFolder to update
     * @param context context of the app
     * @return number of row affected
     */
    public static int forceFoldertoBeRescan(int syncedFolderId, Context context){
        SyncedFolderDAO dao = openSyncedFolderDAO(context, true);
        if(dao == null){
            return -1;
        }

        int result = dao.reduceLastModifiedValue(syncedFolderId);
        dao.close();
        return result;
    }
}
+19 −0
Original line number Diff line number Diff line
@@ -156,6 +156,25 @@ class SyncedFolderDAO {
        return syncedFolders;
    }

    /**
     * reduce to 1 the value stored in lastModified of this syncFolder . The goal is to allow app to resync this folder next time
     * @param syncFolderID if true, return all enabled syncedFolder, if false return all disabled syncedFolder
     * @return number of row affected
     */
    int reduceLastModifiedValue(int syncFolderID) {
        ContentValues values = new ContentValues();
        values.put( SyncedFolderContract.LOCAL_LAST_MODIFIED, 1 );
        int result = 0;
        try{
            result = mDB.update(SyncedFolderContract.TABLE_NAME, values,
                    SyncedFolderContract._ID+" = "+ syncFolderID,
                    null);
        }catch(Exception e){
            Log.e(TAG, e.toString());
        }
        return result;
    }

    /**
    * Create a syncedFolder object from data in cursor.
    * @param cursor cursor containing data to build syncedFolder
+14 −5
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@

package io.eelo.drive.operations;

import android.app.NotificationManager;
import android.content.Context;
import android.util.Log;

@@ -21,6 +22,8 @@ import com.owncloud.android.lib.resources.files.RemoteFile;
import com.owncloud.android.lib.resources.files.UploadRemoteFileOperation;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import io.eelo.drive.database.DbHelper;
@@ -123,7 +126,7 @@ public class UploadFileOperation extends RemoteOperation {
                ( !checkEtag || mSyncedState.getLastETAG().isEmpty() )? null : mSyncedState.getLastETAG(), //If not null, This can cause error 412; that means remote file has change
                timeStamp );
        if(restartCounter == 0) {
            CommonUtils.sendNotification(mContext,notificationID,"Start to upload " + mSyncedState.getName(), android.R.drawable.stat_sys_upload);
            CommonUtils.sendNotification(mContext,notificationID,"Start to upload " + mSyncedState.getName(), android.R.drawable.stat_sys_upload, null, null);
        }

        // Execute UploadFileOperation
@@ -181,7 +184,8 @@ public class UploadFileOperation extends RemoteOperation {
                }

            }else if(uploadResult.getCode() == RemoteOperationResult.ResultCode.QUOTA_EXCEEDED){
                return new RemoteOperationResult( uploadResult.getCode() );
                mResultCode = RemoteOperationResult.ResultCode.QUOTA_EXCEEDED;
                mustRestart = false;
            }else{
                //Upload failed
                Log.e(TAG, "UploadRemoteFileOperation for : " + mFile.getName() + " failed => code: " + uploadResult.getCode());
@@ -196,15 +200,20 @@ public class UploadFileOperation extends RemoteOperation {
                return this.run(client);
            } else {
                mSyncedState.setLocalLastModified( this.previousLastModified); //Revert syncFileState to its previous state
                CommonUtils.sendNotification(mContext,notificationID, "Upload failed for: "+mSyncedState.getName(), android.R.drawable.stat_notify_error );
            }
        }
        // updated syncedFile in DB
        DbHelper.manageSyncedFileStateDB(mSyncedState, "UPDATE", mContext);
        if(mResultCode == RemoteOperationResult.ResultCode.OK) {
            CommonUtils.sendNotification(mContext,notificationID, mSyncedState.getName() + " has been uploaded", android.R.drawable.stat_sys_upload_done);
            CommonUtils.sendNotification(mContext,notificationID, mSyncedState.getName() + " has been uploaded", android.R.drawable.stat_sys_upload_done, null, null);
        }else{
            ( (NotificationManager)  mContext.getSystemService(Context.NOTIFICATION_SERVICE) ).cancel(notificationID);
        }
        return new RemoteOperationResult( mResultCode );
        ArrayList<Object> datas = new ArrayList<>();
        datas.add(mSyncedState.getSyncedFolderId());
        final RemoteOperationResult finalResult = new RemoteOperationResult(mResultCode);
        finalResult.setData(datas);
        return finalResult;
    }

    /**
+2 −2
Original line number Diff line number Diff line
@@ -113,7 +113,7 @@ public class InitializerService extends Service implements OnRemoteOperationList
        this.mCloudClient = (OwnCloudClient) result;
        if (mCloudClient != null) {

            CommonUtils.sendNotification(this,this.notificationID, "Initialisation in process", android.R.drawable.stat_notify_sync);
            CommonUtils.sendNotification(this,this.notificationID, "Initialisation in process", android.R.drawable.stat_notify_sync, null, null);
            if (!isAccountFromPref) {
                SharedPreferences settings = getApplicationContext().getSharedPreferences(
                        AppConstants.SHARED_PREFERENCE_NAME,
@@ -273,7 +273,7 @@ public class InitializerService extends Service implements OnRemoteOperationList
                edit.putBoolean(AppConstants.INITIALIZERSERVICE_HAS_RUN, true)
                        .putInt(INITIALFOLDERS_NUMBER, mSyncedFolders.size())
                        .apply();
                CommonUtils.sendNotification(this,this.notificationID, "Initialisation is over", android.R.drawable.stat_notify_sync_noanim);
                CommonUtils.sendNotification(this,this.notificationID, "Initialisation is over", android.R.drawable.stat_notify_sync_noanim, null, null);
                stopSelf();
            }else {
                startFolderCreation();
+2 −2
Original line number Diff line number Diff line
@@ -432,7 +432,7 @@ public class ObserverService extends Service implements OnRemoteOperationListene
                    Log.d(CURRENTTAG, file.getName()+" doesn't exists *2");
                    //It means that file has been correctly deleted from device. So update DB.
                    if (DbHelper.manageSyncedFileStateDB(syncedFileState, "DELETE", this) > 0)
                        CommonUtils.sendNotification(this,3310, syncedFileState.getName() + " has been removed", android.R.drawable.ic_delete);
                        CommonUtils.sendNotification(this,3310, syncedFileState.getName() + " has been removed", android.R.drawable.ic_delete, null, null);
                    else
                        Log.e(CURRENTTAG, "SyncedFileState row hasn't been deleted from DB");
                }else
@@ -570,7 +570,7 @@ public class ObserverService extends Service implements OnRemoteOperationListene

                        //if File has been modified since last time and or if no lastEtag is stored meaning first sync has failed
                        if( syncedFileState.getLocalLastModified() < localFile.lastModified() || !syncedFileState.isLastEtagStored()){

                            Log.d(TAG+"_toto", syncedFileState.getName()+" has no etag stored or lastModified smaller than local file's last modified" );
                            boolean checkEtag = true;
                            for(int folderIndex =-1, size = mSyncedFolders.size();++folderIndex < size;){
                                final SyncedFolder syncedFolder = mSyncedFolders.get(folderIndex);
Loading