Fixed. App crash when setting a path without slash
[pub/Android/ownCloud.git] / src / com / owncloud / android / operations / SynchronizeFolderOperation.java
index 5d95707..f542652 100644 (file)
@@ -1,5 +1,5 @@
 /* ownCloud Android client application
 /* ownCloud Android client application
- *   Copyright (C) 2012-2013 ownCloud Inc.
+ *   Copyright (C) 2012-2014 ownCloud Inc.
  *
  *   This program is free software: you can redistribute it and/or modify
  *   it under the terms of the GNU General Public License version 2,
  *
  *   This program is free software: you can redistribute it and/or modify
  *   it under the terms of the GNU General Public License version 2,
@@ -43,6 +43,7 @@ import com.owncloud.android.lib.resources.shares.OCShare;
 import com.owncloud.android.lib.common.operations.RemoteOperation;
 import com.owncloud.android.lib.common.operations.RemoteOperationResult;
 import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
 import com.owncloud.android.lib.common.operations.RemoteOperation;
 import com.owncloud.android.lib.common.operations.RemoteOperationResult;
 import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
+import com.owncloud.android.lib.common.utils.Log_OC;
 import com.owncloud.android.lib.resources.shares.GetRemoteSharesForFileOperation;
 import com.owncloud.android.lib.resources.files.FileUtils;
 import com.owncloud.android.lib.resources.files.ReadRemoteFileOperation;
 import com.owncloud.android.lib.resources.shares.GetRemoteSharesForFileOperation;
 import com.owncloud.android.lib.resources.files.FileUtils;
 import com.owncloud.android.lib.resources.files.ReadRemoteFileOperation;
@@ -51,7 +52,6 @@ import com.owncloud.android.lib.resources.files.RemoteFile;
 
 import com.owncloud.android.syncadapter.FileSyncAdapter;
 import com.owncloud.android.utils.FileStorageUtils;
 
 import com.owncloud.android.syncadapter.FileSyncAdapter;
 import com.owncloud.android.utils.FileStorageUtils;
-import com.owncloud.android.utils.Log_OC;
 
 
 
 
 
 
@@ -109,6 +109,9 @@ public class SynchronizeFolderOperation extends RemoteOperation {
     /** 'True' means that the remote folder changed from last synchronization and should be fetched */
     private boolean mRemoteFolderChanged;
 
     /** 'True' means that the remote folder changed from last synchronization and should be fetched */
     private boolean mRemoteFolderChanged;
 
+    /** 'True' means that Etag will be ignored */
+    private boolean mIgnoreETag;
+
     
     /**
      * Creates a new instance of {@link SynchronizeFolderOperation}.
     
     /**
      * Creates a new instance of {@link SynchronizeFolderOperation}.
@@ -126,6 +129,7 @@ public class SynchronizeFolderOperation extends RemoteOperation {
                                         long currentSyncTime, 
                                         boolean syncFullAccount,
                                         boolean isShareSupported,
                                         long currentSyncTime, 
                                         boolean syncFullAccount,
                                         boolean isShareSupported,
+                                        boolean ignoreETag,
                                         FileDataStorageManager dataStorageManager, 
                                         Account account, 
                                         Context context ) {
                                         FileDataStorageManager dataStorageManager, 
                                         Account account, 
                                         Context context ) {
@@ -138,6 +142,7 @@ public class SynchronizeFolderOperation extends RemoteOperation {
         mContext = context;
         mForgottenLocalFiles = new HashMap<String, String>();
         mRemoteFolderChanged = false;
         mContext = context;
         mForgottenLocalFiles = new HashMap<String, String>();
         mRemoteFolderChanged = false;
+        mIgnoreETag = ignoreETag;
     }
     
     
     }
     
     
@@ -192,11 +197,8 @@ public class SynchronizeFolderOperation extends RemoteOperation {
             sendLocalBroadcast(EVENT_SINGLE_FOLDER_CONTENTS_SYNCED, mLocalFolder.getRemotePath(), result);
         }
         
             sendLocalBroadcast(EVENT_SINGLE_FOLDER_CONTENTS_SYNCED, mLocalFolder.getRemotePath(), result);
         }
         
-        if (result.isSuccess() && mIsShareSupported) {
-            RemoteOperationResult shareResult = refreshSharesForFolder(client);
-            if (shareResult.getCode() != ResultCode.FILE_NOT_FOUND) {
-                result = shareResult;
-            } // else , keep the previous result ; being conservative for servers where Sharing API is supported, but disabled
+        if (result.isSuccess() && mIsShareSupported && !mSyncFullAccount) {
+            refreshSharesForFolder(client); // share result is ignored 
         }
         
         if (!mSyncFullAccount) {            
         }
         
         if (!mSyncFullAccount) {            
@@ -218,7 +220,7 @@ public class SynchronizeFolderOperation extends RemoteOperation {
 
     
     private RemoteOperationResult checkForChanges(OwnCloudClient client) {
 
     
     private RemoteOperationResult checkForChanges(OwnCloudClient client) {
-        mRemoteFolderChanged = false;
+        mRemoteFolderChanged = true;
         RemoteOperationResult result = null;
         String remotePath = null;
 
         RemoteOperationResult result = null;
         String remotePath = null;
 
@@ -230,10 +232,12 @@ public class SynchronizeFolderOperation extends RemoteOperation {
         result = operation.execute(client);
         if (result.isSuccess()){
             OCFile remoteFolder = FileStorageUtils.fillOCFile((RemoteFile) result.getData().get(0));
         result = operation.execute(client);
         if (result.isSuccess()){
             OCFile remoteFolder = FileStorageUtils.fillOCFile((RemoteFile) result.getData().get(0));
-            
-            // check if remote and local folder are different
-            mRemoteFolderChanged = !(remoteFolder.getEtag().equalsIgnoreCase(mLocalFolder.getEtag()));
-          
+
+            if (!mIgnoreETag) {
+                // check if remote and local folder are different
+                mRemoteFolderChanged = !(remoteFolder.getEtag().equalsIgnoreCase(mLocalFolder.getEtag()));
+            }
+
             result = new RemoteOperationResult(ResultCode.OK);
         
             Log_OC.i(TAG, "Checked " + mAccount.name + remotePath + " : " + (mRemoteFolderChanged ? "changed" : "not changed"));
             result = new RemoteOperationResult(ResultCode.OK);
         
             Log_OC.i(TAG, "Checked " + mAccount.name + remotePath + " : " + (mRemoteFolderChanged ? "changed" : "not changed"));
@@ -339,6 +343,8 @@ public class SynchronizeFolderOperation extends RemoteOperation {
                 if (remoteFile.isFolder()) {
                     remoteFile.setFileLength(localFile.getFileLength()); // TODO move operations about size of folders to FileContentProvider
                 }
                 if (remoteFile.isFolder()) {
                     remoteFile.setFileLength(localFile.getFileLength()); // TODO move operations about size of folders to FileContentProvider
                 }
+                remoteFile.setPublicLink(localFile.getPublicLink());
+                remoteFile.setShareByLink(localFile.isShareByLink());
             } else {
                 remoteFile.setEtag(""); // remote eTag will not be updated unless contents are synchronized (Synchronize[File|Folder]Operation with remoteFile as parameter)
             }
             } else {
                 remoteFile.setEtag(""); // remote eTag will not be updated unless contents are synchronized (Synchronize[File|Folder]Operation with remoteFile as parameter)
             }
@@ -351,11 +357,11 @@ public class SynchronizeFolderOperation extends RemoteOperation {
             if (remoteFile.keepInSync()) {
                 SynchronizeFileOperation operation = new SynchronizeFileOperation(  localFile,        
                                                                                     remoteFile, 
             if (remoteFile.keepInSync()) {
                 SynchronizeFileOperation operation = new SynchronizeFileOperation(  localFile,        
                                                                                     remoteFile, 
-                                                                                    mStorageManager,
-                                                                                    mAccount,       
+                                                                                    mAccount, 
                                                                                     true, 
                                                                                     mContext
                                                                                     );
                                                                                     true, 
                                                                                     mContext
                                                                                     );
+                
                 filesToSyncContents.add(operation);
             }
             
                 filesToSyncContents.add(operation);
             }
             
@@ -383,7 +389,7 @@ public class SynchronizeFolderOperation extends RemoteOperation {
     private void startContentSynchronizations(List<SynchronizeFileOperation> filesToSyncContents, OwnCloudClient client) {
         RemoteOperationResult contentsResult = null;
         for (SynchronizeFileOperation op: filesToSyncContents) {
     private void startContentSynchronizations(List<SynchronizeFileOperation> filesToSyncContents, OwnCloudClient client) {
         RemoteOperationResult contentsResult = null;
         for (SynchronizeFileOperation op: filesToSyncContents) {
-            contentsResult = op.execute(client);   // returns without waiting for upload or download finishes
+            contentsResult = op.execute(mStorageManager, mContext);   // returns without waiting for upload or download finishes
             if (!contentsResult.isSuccess()) {
                 if (contentsResult.getCode() == ResultCode.SYNC_CONFLICT) {
                     mConflictsFound++;
             if (!contentsResult.isSuccess()) {
                 if (contentsResult.getCode() == ResultCode.SYNC_CONFLICT) {
                     mConflictsFound++;
@@ -417,6 +423,8 @@ public class SynchronizeFolderOperation extends RemoteOperation {
         file.setMimetype(remote.getMimeType());
         file.setModificationTimestamp(remote.getModifiedTimestamp());
         file.setEtag(remote.getEtag());
         file.setMimetype(remote.getMimeType());
         file.setModificationTimestamp(remote.getModifiedTimestamp());
         file.setEtag(remote.getEtag());
+        file.setPermissions(remote.getPermissions());
+        file.setRemoteId(remote.getRemoteId());
         return file;
     }
     
         return file;
     }