X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/015eb6fee99b59abab2f70bb67cf7b6cda191620..refs/heads/master:/src/com/owncloud/android/operations/RefreshFolderOperation.java diff --git a/src/com/owncloud/android/operations/RefreshFolderOperation.java b/src/com/owncloud/android/operations/RefreshFolderOperation.java index 2e3c4692..368833e5 100644 --- a/src/com/owncloud/android/operations/RefreshFolderOperation.java +++ b/src/com/owncloud/android/operations/RefreshFolderOperation.java @@ -20,26 +20,17 @@ package com.owncloud.android.operations; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Vector; -import org.apache.http.HttpStatus; import android.accounts.Account; import android.content.Context; import android.content.Intent; import android.util.Log; -//import android.support.v4.content.LocalBroadcastManager; -import com.owncloud.android.MainApp; import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.datamodel.OCFile; @@ -50,7 +41,6 @@ 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.files.ReadRemoteFolderOperation; import com.owncloud.android.lib.resources.files.RemoteFile; @@ -120,7 +110,10 @@ public class RefreshFolderOperation extends RemoteOperation { /** 'True' means that Etag will be ignored */ private boolean mIgnoreETag; - + private List mFilesToSyncContents; + // this will be used for every file when 'folder synchronization' replaces 'folder download' + + /** * Creates a new instance of {@link RefreshFolderOperation}. * @@ -154,6 +147,7 @@ public class RefreshFolderOperation extends RemoteOperation { mForgottenLocalFiles = new HashMap(); mRemoteFolderChanged = false; mIgnoreETag = ignoreETag; + mFilesToSyncContents = new Vector(); } @@ -191,8 +185,9 @@ public class RefreshFolderOperation extends RemoteOperation { mConflictsFound = 0; mForgottenLocalFiles.clear(); - if (FileUtils.PATH_SEPARATOR.equals(mLocalFolder.getRemotePath()) && !mSyncFullAccount) { + if (OCFile.ROOT_PATH.equals(mLocalFolder.getRemotePath()) && !mSyncFullAccount) { updateOCVersion(client); + } result = checkForChanges(client); @@ -201,9 +196,14 @@ public class RefreshFolderOperation extends RemoteOperation { if (mRemoteFolderChanged) { result = fetchAndSyncRemoteFolder(client); } else { - // TODO Enable when "On Device" is recovered ? + fetchFavoritesToSyncFromLocalData(); mChildren = mStorageManager.getFolderContent(mLocalFolder/*, false*/); } + + if (result.isSuccess()) { + // request for the synchronization of KEPT-IN-SYNC file contents + startContentSynchronizations(mFilesToSyncContents, client); + } } if (!mSyncFullAccount) { @@ -232,16 +232,29 @@ public class RefreshFolderOperation extends RemoteOperation { RemoteOperationResult result = update.execute(client); if (result.isSuccess()) { mIsShareSupported = update.getOCVersion().isSharedSupported(); + + // Update Capabilities for this account + if (update.getOCVersion().isVersionWithCapabilitiesAPI()) { + updateCapabilities(client); + } else { + Log_OC.d(TAG, "Capabilities API disabled"); + } + } + } + + private void updateCapabilities(OwnCloudClient client){ + GetCapabilitiesOperarion getCapabilities = new GetCapabilitiesOperarion(); + RemoteOperationResult result = getCapabilities.execute(mStorageManager,mContext); + if (!result.isSuccess()){ + Log_OC.w(TAG, "Update Capabilities unsuccessfully"); } } - private RemoteOperationResult checkForChanges(OwnCloudClient client) { mRemoteFolderChanged = true; RemoteOperationResult result = null; - String remotePath = null; + String remotePath = mLocalFolder.getRemotePath(); - remotePath = mLocalFolder.getRemotePath(); Log_OC.d(TAG, "Checking changes in " + mAccount.name + remotePath); // remote request @@ -252,13 +265,19 @@ public class RefreshFolderOperation extends RemoteOperation { if (!mIgnoreETag) { // check if remote and local folder are different - mRemoteFolderChanged = - !(remoteFolder.getEtag().equalsIgnoreCase(mLocalFolder.getEtag())); + String remoteFolderETag = remoteFolder.getEtag(); + if (remoteFolderETag != null) { + mRemoteFolderChanged = + !(remoteFolderETag.equalsIgnoreCase(mLocalFolder.getEtag())); + } else { + Log_OC.e(TAG, "Checked " + mAccount.name + remotePath + " : " + + "No ETag received from server"); + } } result = new RemoteOperationResult(ResultCode.OK); - Log_OC.i(TAG, "Checked " + mAccount.name + remotePath + " : " + + Log_OC.i(TAG, "Checked " + mAccount.name + remotePath + " : " + (mRemoteFolderChanged ? "changed" : "not changed")); } else { @@ -331,15 +350,15 @@ public class RefreshFolderOperation extends RemoteOperation { mLocalFolder = mStorageManager.getFileByPath(mLocalFolder.getRemotePath()); // parse data from remote folder - OCFile remoteFolder = fillOCFile((RemoteFile)folderAndFiles.get(0)); + OCFile remoteFolder = FileStorageUtils.fillOCFile((RemoteFile) folderAndFiles.get(0)); remoteFolder.setParentId(mLocalFolder.getParentId()); remoteFolder.setFileId(mLocalFolder.getFileId()); - Log_OC.d(TAG, "Remote folder " + mLocalFolder.getRemotePath() + Log_OC.d(TAG, "Remote folder " + mLocalFolder.getRemotePath() + " changed - starting update of local data "); List updatedFiles = new Vector(folderAndFiles.size() - 1); - List filesToSyncContents = new Vector(); + mFilesToSyncContents.clear(); // get current data about local contents of the folder to synchronize // TODO Enable when "On Device" is recovered ? @@ -350,54 +369,56 @@ public class RefreshFolderOperation extends RemoteOperation { } // loop to update every child - OCFile remoteFile = null, localFile = null; + OCFile remoteFile = null, localFile = null, updatedFile = null; + RemoteFile r; for (int i=1; i 0){ - out.write(buf, 0, len); - } - file.setStoragePath(expectedPath); - - } catch (Exception e) { - Log_OC.e(TAG, "Exception while copying foreign file " + expectedPath, e); - mForgottenLocalFiles.put(file.getRemotePath(), storagePath); - file.setStoragePath(null); - - } finally { - try { - if (in != null) in.close(); - } catch (Exception e) { - Log_OC.d(TAG, "Weird exception while closing input stream for " - + storagePath + " (ignoring)", e); - } - try { - if (out != null) out.close(); - } catch (Exception e) { - Log_OC.d(TAG, "Weird exception while closing output stream for " - + expectedPath + " (ignoring)", e); - } - } - } - } - } - - private RemoteOperationResult refreshSharesForFolder(OwnCloudClient client) { RemoteOperationResult result = null; // remote request GetRemoteSharesForFileOperation operation = - new GetRemoteSharesForFileOperation(mLocalFolder.getRemotePath(), false, true); + new GetRemoteSharesForFileOperation(mLocalFolder.getRemotePath(), true, true); result = operation.execute(client); if (result.isSuccess()) { @@ -567,24 +501,6 @@ public class RefreshFolderOperation extends RemoteOperation { /** - * Scans the default location for saving local copies of files searching for - * a 'lost' file with the same full name as the {@link OCFile} received as - * parameter. - * - * @param file File to associate a possible 'lost' local file. - */ - private void searchForLocalFileInDefaultPath(OCFile file) { - if (file.getStoragePath() == null && !file.isFolder()) { - File f = new File(FileStorageUtils.getDefaultSavePathFor(mAccount.name, file)); - if (f.exists()) { - file.setStoragePath(f.getAbsolutePath()); - file.setLastSyncDateForData(f.lastModified()); - } - } - } - - - /** * Sends a message to any application component interested in the progress * of the synchronization. * @@ -608,8 +524,20 @@ public class RefreshFolderOperation extends RemoteOperation { } - public boolean getRemoteFolderChanged() { - return mRemoteFolderChanged; + private void fetchFavoritesToSyncFromLocalData() { + List children = mStorageManager.getFolderContent(mLocalFolder); + for (OCFile child : children) { + if (!child.isFolder() && child.isFavorite()) { + SynchronizeFileOperation operation = new SynchronizeFileOperation( + child, + child, // cheating with the remote file to get an update to server; to refactor + mAccount, + true, + mContext + ); + mFilesToSyncContents.add(operation); + } + } } }