Переглянути джерело

Fix Select Local Version or Keep Both behaviour when solving file coflict

masensio 9 роки тому
батько
коміт
bcfa07f565

+ 14 - 16
src/com/owncloud/android/datamodel/FileDataStorageManager.java

@@ -197,7 +197,7 @@ public class FileDataStorageManager {
         cv.put(ProviderTableMeta.FILE_REMOTE_ID, file.getRemoteId());
         cv.put(ProviderTableMeta.FILE_UPDATE_THUMBNAIL, file.needsUpdateThumbnail());
         cv.put(ProviderTableMeta.FILE_IS_DOWNLOADING, file.isDownloading());
-        cv.put(ProviderTableMeta.FILE_IN_CONFLICT, file.isInConflict());
+        cv.put(ProviderTableMeta.FILE_ETAG_IN_CONFLICT, file.getEtagInConflict());
 
         boolean sameRemotePath = fileExists(file.getRemotePath());
         if (sameRemotePath ||                fileExists(file.getFileId())) {           // for renamed files; no more delete and create
@@ -301,7 +301,7 @@ public class FileDataStorageManager {
             cv.put(ProviderTableMeta.FILE_REMOTE_ID, file.getRemoteId());
             cv.put(ProviderTableMeta.FILE_UPDATE_THUMBNAIL, file.needsUpdateThumbnail());
             cv.put(ProviderTableMeta.FILE_IS_DOWNLOADING, file.isDownloading());
-            cv.put(ProviderTableMeta.FILE_IN_CONFLICT, file.isInConflict());
+            cv.put(ProviderTableMeta.FILE_ETAG_IN_CONFLICT, file.getEtagInConflict());
 
             boolean existsByPath = fileExists(file.getRemotePath());
             if (existsByPath || fileExists(file.getFileId())) {
@@ -459,7 +459,7 @@ public class FileDataStorageManager {
                         // maybe unnecessary, but should be checked TODO remove if unnecessary
                         file.setStoragePath(null);
                         saveFile(file);
-                        saveConflict(file, false);
+                        saveConflict(file, null);
                     }
                 }
             }
@@ -897,8 +897,7 @@ public class FileDataStorageManager {
                     c.getColumnIndex(ProviderTableMeta.FILE_UPDATE_THUMBNAIL)) == 1 ? true : false);
             file.setDownloading(c.getInt(
                     c.getColumnIndex(ProviderTableMeta.FILE_IS_DOWNLOADING)) == 1 ? true : false);
-            file.setInConflict(c.getInt(
-                    c.getColumnIndex(ProviderTableMeta.FILE_IN_CONFLICT)) == 1 ? true : false);
+            file.setEtagInConflict(c.getString(c.getColumnIndex(ProviderTableMeta.FILE_ETAG_IN_CONFLICT)));
 
         }
         return file;
@@ -1234,10 +1233,7 @@ public class FileDataStorageManager {
                         ProviderTableMeta.FILE_IS_DOWNLOADING,
                         file.isDownloading() ? 1 : 0
                 );
-                cv.put(
-                        ProviderTableMeta.FILE_IN_CONFLICT,
-                        file.isInConflict() ? 1 : 0
-                );
+                cv.put(ProviderTableMeta.FILE_ETAG_IN_CONFLICT, file.getEtagInConflict());
 
                 boolean existsByPath = fileExists(file.getRemotePath());
                 if (existsByPath || fileExists(file.getFileId())) {
@@ -1468,12 +1464,12 @@ public class FileDataStorageManager {
 
     }
 
-    public void saveConflict(OCFile file, boolean inConflict) {
+    public void saveConflict(OCFile file, String etagInConflict) {
         if (!file.isDown()) {
-            inConflict = false;
+            etagInConflict = null;
         }
         ContentValues cv = new ContentValues();
-        cv.put(ProviderTableMeta.FILE_IN_CONFLICT, inConflict ? 1 : 0);
+        cv.put(ProviderTableMeta.FILE_ETAG_IN_CONFLICT, etagInConflict);
         int updated = 0;
         if (getContentResolver() != null) {
             updated = getContentResolver().update(
@@ -1498,7 +1494,7 @@ public class FileDataStorageManager {
         Log_OC.d(TAG, "Number of files updated with CONFLICT: " + updated);
 
         if (updated > 0) {
-            if (inConflict) {
+            if (etagInConflict != null) {
                 /// set conflict in all ancestor folders
 
                 long parentId = file.getParentId();
@@ -1551,7 +1547,7 @@ public class FileDataStorageManager {
                 while (parentPath.length() > 0) {
 
                     String where =
-                            ProviderTableMeta.FILE_IN_CONFLICT + " = 1 AND " +
+                            ProviderTableMeta.FILE_ETAG_IN_CONFLICT + " IS NOT NULL AND " +
                                     ProviderTableMeta.FILE_CONTENT_TYPE + " != 'DIR' AND " +
                                     ProviderTableMeta.FILE_ACCOUNT_OWNER + " = ? AND " +
                                     ProviderTableMeta.FILE_PATH + " LIKE ?";
@@ -1568,7 +1564,8 @@ public class FileDataStorageManager {
                             updated = getContentResolver().update(
                                     ProviderTableMeta.CONTENT_URI_FILE,
                                     cv,
-                                    ProviderTableMeta.FILE_ACCOUNT_OWNER + "=? AND " + ProviderTableMeta.FILE_PATH + "=?",
+                                    ProviderTableMeta.FILE_ACCOUNT_OWNER + "=? AND " +
+                                            ProviderTableMeta.FILE_PATH + "=?",
                                     new String[]{mAccount.name, parentPath}
                             );
                         } else {
@@ -1576,7 +1573,8 @@ public class FileDataStorageManager {
                                 updated = getContentProviderClient().update(
                                         ProviderTableMeta.CONTENT_URI_FILE,
                                         cv,
-                                        ProviderTableMeta.FILE_ACCOUNT_OWNER + "=? AND " + ProviderTableMeta.FILE_PATH + "=?"
+                                        ProviderTableMeta.FILE_ACCOUNT_OWNER + "=? AND " +
+                                                ProviderTableMeta.FILE_PATH + "=?"
                                         , new String[]{mAccount.name, parentPath}
                                 );
                             } catch (RemoteException e) {

+ 8 - 8
src/com/owncloud/android/datamodel/OCFile.java

@@ -74,7 +74,7 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
 
     private boolean mIsDownloading;
 
-    private boolean mInConflict;
+    private String mEtagInConflict;    // Save file etag in the server, when there is a conflict. No conflict =  null
 
 
     /**
@@ -119,7 +119,7 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
         mRemoteId = source.readString();
         mNeedsUpdateThumbnail = source.readInt() == 1;
         mIsDownloading = source.readInt() == 1;
-        mInConflict = source.readInt() == 1;
+        mEtagInConflict = source.readString();
 
     }
 
@@ -145,7 +145,7 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
         dest.writeString(mRemoteId);
         dest.writeInt(mNeedsUpdateThumbnail ? 1 : 0);
         dest.writeInt(mIsDownloading ? 1 : 0);
-        dest.writeInt(mInConflict ? 1 : 0);
+        dest.writeString(mEtagInConflict);
     }
 
     /**
@@ -343,7 +343,7 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
         mRemoteId = null;
         mNeedsUpdateThumbnail = false;
         mIsDownloading = false;
-        mInConflict = false;
+        mEtagInConflict = null;
     }
 
     /**
@@ -584,11 +584,11 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
         this.mIsDownloading = isDownloading;
     }
 
-    public boolean isInConflict() {
-        return mInConflict;
+    public String getEtagInConflict() {
+        return mEtagInConflict;
     }
 
-    public void setInConflict(boolean inConflict) {
-        mInConflict = inConflict;
+    public void setEtagInConflict(String etagInConflict) {
+        mEtagInConflict = etagInConflict;
     }
 }

+ 1 - 1
src/com/owncloud/android/db/ProviderMeta.java

@@ -72,7 +72,7 @@ public class ProviderMeta {
         public static final String FILE_REMOTE_ID = "remote_id";
         public static final String FILE_UPDATE_THUMBNAIL = "update_thumbnail";
         public static final String FILE_IS_DOWNLOADING= "is_downloading";
-        public static final String FILE_IN_CONFLICT = "in_conflict";
+        public static final String FILE_ETAG_IN_CONFLICT = "etag_in_conflict";
 
         public static final String FILE_DEFAULT_SORT_ORDER = FILE_NAME
                 + " collate nocase asc";

+ 1 - 1
src/com/owncloud/android/files/services/FileDownloader.java

@@ -471,7 +471,7 @@ public class FileDownloader extends Service
         file.setRemoteId(mCurrentDownload.getFile().getRemoteId());
         mStorageManager.saveFile(file);
         mStorageManager.triggerMediaScan(file.getStoragePath());
-        mStorageManager.saveConflict(file, false);
+        mStorageManager.saveConflict(file, null);
     }
 
     /**

+ 4 - 3
src/com/owncloud/android/files/services/FileUploader.java

@@ -574,7 +574,8 @@ public class FileUploader extends Service
                             saveUploadedFile();
 
                         } else if (uploadResult.getCode() == ResultCode.SYNC_CONFLICT) {
-                            mStorageManager.saveConflict(mCurrentUpload.getFile(), true);
+                            mStorageManager.saveConflict(mCurrentUpload.getFile(),
+                                    mCurrentUpload.getFile().getEtagInConflict());
                         }
                     } else {
                         uploadResult = grantResult;
@@ -704,7 +705,7 @@ public class FileUploader extends Service
             if (oldFile.fileExists()) {
                 oldFile.setStoragePath(null);
                 mStorageManager.saveFile(oldFile);
-                mStorageManager.saveConflict(oldFile, false);
+                mStorageManager.saveConflict(oldFile, null);
 
             } // else: it was just an automatic renaming due to a name
             // coincidence; nothing else is needed, the storagePath is right
@@ -712,7 +713,7 @@ public class FileUploader extends Service
         }
         file.setNeedsUpdateThumbnail(true);
         mStorageManager.saveFile(file);
-        mStorageManager.saveConflict(file, false);
+        mStorageManager.saveConflict(file, null);
         
         mStorageManager.triggerMediaScan(file.getStoragePath());
 

+ 1 - 1
src/com/owncloud/android/operations/RefreshFolderOperation.java

@@ -392,7 +392,7 @@ public class RefreshFolderOperation extends RemoteOperation {
                 }
                 updatedFile.setPublicLink(localFile.getPublicLink());
                 updatedFile.setShareByLink(localFile.isShareByLink());
-                updatedFile.setInConflict(localFile.isInConflict());
+                updatedFile.setEtagInConflict(localFile.getEtagInConflict());
             } else {
                 // remote eTag will not be updated unless file CONTENTS are synchronized
                 updatedFile.setEtag("");

+ 2 - 2
src/com/owncloud/android/operations/SynchronizeFileOperation.java

@@ -222,7 +222,7 @@ public class SynchronizeFileOperation extends SyncOperation {
                 //if (!mLocalFile.getEtag().isEmpty() && localChanged && serverChanged) {
                 if (localChanged && serverChanged) {
                     result = new RemoteOperationResult(ResultCode.SYNC_CONFLICT);
-                    getStorageManager().saveConflict(mLocalFile, true);
+                    getStorageManager().saveConflict(mLocalFile, mServerFile.getEtag());
 
                 } else if (localChanged) {
                     if (mSyncFileContents && mAllowUploads) {
@@ -265,7 +265,7 @@ public class SynchronizeFileOperation extends SyncOperation {
 
                 // safe blanket: sync'ing a not in-conflict file will clean wrong conflict markers in ancestors
                 if (result.getCode() != ResultCode.SYNC_CONFLICT) {
-                    getStorageManager().saveConflict(mLocalFile, false);
+                    getStorageManager().saveConflict(mLocalFile, null);
                 }
             }
 

+ 2 - 2
src/com/owncloud/android/operations/SynchronizeFolderOperation.java

@@ -340,7 +340,7 @@ public class SynchronizeFolderOperation extends SyncOperation {
                 }
                 updatedFile.setPublicLink(localFile.getPublicLink());
                 updatedFile.setShareByLink(localFile.isShareByLink());
-                updatedFile.setInConflict(localFile.isInConflict());
+                updatedFile.setEtagInConflict(localFile.getEtagInConflict());
             } else {
                 // remote eTag will not be updated unless file CONTENTS are synchronized
                 updatedFile.setEtag("");
@@ -404,7 +404,7 @@ public class SynchronizeFolderOperation extends SyncOperation {
                     /// this should result in direct upload of files that were locally modified
                     SynchronizeFileOperation operation = new SynchronizeFileOperation(
                             child,
-                            (child.isInConflict() ? null : child),
+                            (child.getEtagInConflict() != null ? null : child),
                             mAccount,
                             true,
                             mContext

+ 2 - 2
src/com/owncloud/android/operations/UploadFileOperation.java

@@ -311,10 +311,10 @@ public class UploadFileOperation extends RemoteOperation {
                     (new File(mFile.getStoragePath())).length() >
                             ChunkedUploadRemoteFileOperation.CHUNK_SIZE ) {
                 mUploadOperation = new ChunkedUploadRemoteFileOperation(mFile.getStoragePath(),
-                        mFile.getRemotePath(), mFile.getMimetype(), mFile.getEtag());
+                        mFile.getRemotePath(), mFile.getMimetype(), mFile.getEtagInConflict());
             } else {
                 mUploadOperation = new UploadRemoteFileOperation(mFile.getStoragePath(),
-                        mFile.getRemotePath(), mFile.getMimetype(), mFile.getEtag());
+                        mFile.getRemotePath(), mFile.getMimetype(), mFile.getEtagInConflict());
             }
             Iterator <OnDatatransferProgressListener> listener = mDataTransferListeners.iterator();
             while (listener.hasNext()) {

+ 5 - 5
src/com/owncloud/android/providers/FileContentProvider.java

@@ -106,8 +106,8 @@ public class FileContentProvider extends ContentProvider {
                 ProviderTableMeta.FILE_UPDATE_THUMBNAIL);
         mFileProjectionMap.put(ProviderTableMeta.FILE_IS_DOWNLOADING,
                 ProviderTableMeta.FILE_IS_DOWNLOADING);
-        mFileProjectionMap.put(ProviderTableMeta.FILE_IN_CONFLICT,
-                ProviderTableMeta.FILE_IN_CONFLICT);
+        mFileProjectionMap.put(ProviderTableMeta.FILE_ETAG_IN_CONFLICT,
+                ProviderTableMeta.FILE_ETAG_IN_CONFLICT);
     }
 
     private static final int SINGLE_FILE = 1;
@@ -585,7 +585,7 @@ public class FileContentProvider extends ContentProvider {
                     + ProviderTableMeta.FILE_REMOTE_ID  + " TEXT null,"
                     + ProviderTableMeta.FILE_UPDATE_THUMBNAIL  + " INTEGER," //boolean
                     + ProviderTableMeta.FILE_IS_DOWNLOADING  + " INTEGER," //boolean
-                    + ProviderTableMeta.FILE_IN_CONFLICT + " INTEGER);"    //boolean
+                    + ProviderTableMeta.FILE_ETAG_IN_CONFLICT + " TEXT);"
                     );
 
             // Create table ocshares
@@ -791,8 +791,8 @@ public class FileContentProvider extends ContentProvider {
                 db.beginTransaction();
                 try {
                     db .execSQL("ALTER TABLE " + ProviderTableMeta.FILE_TABLE_NAME +
-                            " ADD COLUMN " + ProviderTableMeta.FILE_IN_CONFLICT + " INTEGER " +
-                            " DEFAULT 0");
+                            " ADD COLUMN " + ProviderTableMeta.FILE_ETAG_IN_CONFLICT + " TEXT " +
+                            " DEFAULT NULL");
                     upgraded = true;
                     db.setTransactionSuccessful();
                 } finally {

+ 1 - 1
src/com/owncloud/android/ui/adapter/FileListListAdapter.java

@@ -283,7 +283,7 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
                         );
                         localStateView.setVisibility(View.VISIBLE);
 
-                    } else if (file.isInConflict()) {   // conflict
+                    } else if (file.getEtagInConflict() != null) {   // conflict
                         localStateView.setImageResource(R.drawable.conflict_file_indicator);
                         localStateView.setVisibility(View.VISIBLE);