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

Commit 9d5415cd authored by Vincent Bourgmayer's avatar Vincent Bourgmayer
Browse files

Implement to unchanged directory for which there is some files to download

parent c3bab780
Loading
Loading
Loading
Loading
Loading
+23 −0
Original line number Diff line number Diff line
@@ -298,6 +298,12 @@ public final class DbHelper extends SQLiteOpenHelper {
        return result;
    }

    /**
     * Look if there is some known file that need to be uploaded for the given syncedFolder
     * @param syncedFolderID id of the syncedFolder
     * @param context context
     * @return true if there is at least one file that need to be uploaded
     */
    public static boolean syncedFolderHasContentToUpload(long syncedFolderID, Context context) {
        final SyncedFileStateDAO dao;
        try {
@@ -309,6 +315,23 @@ public final class DbHelper extends SQLiteOpenHelper {
        return false;
    }

    /**
     * Look if there us some known file that need to be downloaded for the given syncedFolder
     * @param syncedFolderId SyncedFolderId
     * @param context context
     * @return true if there is at least one file to download
     */
    public static boolean syncedFolderHasContentToDownload(int syncedFolderId, Context context) {
        final SyncedFileStateDAO dao;
        try {
            dao = openSyncedFileStateDAO(context, false);
            return dao.countFileWaitingForDownloadForSyncedFolder(syncedFolderId) > 0;
        } catch (SQLiteException e) {
            Log.e(TAG, "SQLite error", e);
        }
        return false;
    }

    /**
     * Copy database file into user accessible directory for debuging purpose
     * @return path to the dump or null if failure
+22 −1
Original line number Diff line number Diff line
@@ -148,7 +148,7 @@ class SyncedFileStateDAO {
     * ONLY list file that can be scan on device side
     * @param syncedFolderId ID of the given synced folder
     * @return number of file waiting to be uploaded
     * @throws SQLiteDoneException SQL return 0 row
     * @throws SQLiteDoneException SQL return 0 rows
     */
    long countFileWaitingForUploadForSyncedFolder(long syncedFolderId) throws SQLiteDoneException {
        final String query = "SELECT COUNT(*) FROM "
@@ -161,6 +161,25 @@ class SyncedFileStateDAO {
        return statement.simpleQueryForLong();
    }

    /**
     * Count number of syncedFileState's entry with an eTag but no value for local last modified
     * Only file that can be scan on cloud are listed
     * @param syncedFolderId The id of the syncedFolder
     * @return number of file waiting to be downloaded
     * @throws SQLiteDoneException SQL return 0 rows
     */
    long countFileWaitingForDownloadForSyncedFolder(int syncedFolderId) throws SQLiteDoneException{
        final String query = "SELECT COUNT(*) FROM "
                + TABLE_NAME
                + " WHERE " + SCANNABLE + " IN (1,3)"
                + " AND " + LOCAL_LAST_MODIFIED + " = 0"
                + " AND length(" + LAST_ETAG + ") > 0"
                + " AND " + SYNCEDFOLDER_ID + " = "+syncedFolderId;

        final SQLiteStatement statement = mDB.compileStatement(query);
        return statement.simpleQueryForLong();
    }

    /**
    * Fetch many SyncedFileState by their syncedFolder's id
    * @param syncedFolderIds List<Long> of id of parent syncedFolder.
@@ -254,4 +273,6 @@ class SyncedFileStateDAO {
                cursor.getInt(8) //scannable
        );
    }


}
+2 −1
Original line number Diff line number Diff line
@@ -113,7 +113,8 @@ public class ListFileRemoteOperation extends RemoteOperation<ArrayList<RemoteFil
        final int dataSize = result.getData().size();
        final RemoteFile directory = (RemoteFile) result.getData().get(0);

        if (directory.getEtag().equals(syncedFolder.getLastEtag())) {
        if (directory.getEtag().equals(syncedFolder.getLastEtag())
        && !DbHelper.syncedFolderHasContentToDownload(syncedFolder.getId(), context)) {
            return false;
        }
        syncedFolder.setLastEtag(directory.getEtag()).setToSync(true);