- // removal of obsolete files
- mChildren = mStorageManager.getDirectoryContent(mStorageManager.getFileById(mParentId));
- //OCFile file;
- String currentSavePath = FileStorageUtils.getSavePath(mAccount.name);
- for (OCFile fileChild: mChildren) {
- //file = mChildren.get(i);
- //if (file.getLastSyncDateForProperties() != mCurrentSyncTime) {
- if (!filesOnServer.contains(fileChild.getRemotePath())) {
- Log_OC.d(TAG, "removing file: " + fileChild.getFileName());
- mStorageManager.removeFile(fileChild, (fileChild.isDown() && fileChild.getStoragePath().startsWith(currentSavePath)));
- mChildren.remove(fileChild); //.remove(i);
+ // get current data about local contents of the folder to synchronize
+ // TODO Enable when "On Device" is recovered ?
+ List<OCFile> localFiles = storageManager.getFolderContent(mLocalFolder/*, false*/);
+ Map<String, OCFile> localFilesMap = new HashMap<String, OCFile>(localFiles.size());
+ for (OCFile file : localFiles) {
+ localFilesMap.put(file.getRemotePath(), file);
+ }
+
+ // loop to synchronize every child
+ OCFile remoteFile = null, localFile = null;
+ for (int i=1; i<folderAndFiles.size(); i++) {
+ /// new OCFile instance with the data from the server
+ remoteFile = fillOCFile((RemoteFile)folderAndFiles.get(i));
+ remoteFile.setParentId(mLocalFolder.getFileId());
+
+ /// retrieve local data for the read file
+ // localFile = mStorageManager.getFileByPath(remoteFile.getRemotePath());
+ localFile = localFilesMap.remove(remoteFile.getRemotePath());
+
+ /// add to the remoteFile (the new one) data about LOCAL STATE (not existing in server)
+ remoteFile.setLastSyncDateForProperties(mCurrentSyncTime);
+ if (localFile != null) {
+ // some properties of local state are kept unmodified
+ remoteFile.setFileId(localFile.getFileId());
+ remoteFile.setFavorite(localFile.isFavorite());
+ remoteFile.setLastSyncDateForData(localFile.getLastSyncDateForData());
+ remoteFile.setModificationTimestampAtLastSyncForData(
+ localFile.getModificationTimestampAtLastSyncForData()
+ );
+ remoteFile.setStoragePath(localFile.getStoragePath());
+ // eTag will not be updated unless contents are synchronized
+ // (Synchronize[File|Folder]Operation with remoteFile as parameter)
+ remoteFile.setEtag(localFile.getEtag());
+ if (remoteFile.isFolder()) {
+ remoteFile.setFileLength(localFile.getFileLength());
+ // TODO move operations about size of folders to FileContentProvider
+ } else if (mRemoteFolderChanged && remoteFile.isImage() &&
+ remoteFile.getModificationTimestamp() !=
+ localFile.getModificationTimestamp()) {
+ remoteFile.setNeedsUpdateThumbnail(true);
+ Log.d(TAG, "Image " + remoteFile.getFileName() + " updated on the server");
+ }
+ remoteFile.setPublicLink(localFile.getPublicLink());
+ remoteFile.setShareByLink(localFile.isShareByLink());
+ } else {
+ // remote eTag will not be updated unless contents are synchronized
+ // (Synchronize[File|Folder]Operation with remoteFile as parameter)
+ remoteFile.setEtag("");
+ }
+
+ /// check and fix, if needed, local storage path
+ searchForLocalFileInDefaultPath(remoteFile);
+
+ /// classify file to sync/download contents later
+ if (remoteFile.isFolder()) {
+ /// to download children files recursively
+ synchronized (mCancellationRequested) {
+ if (mCancellationRequested.get()) {
+ throw new OperationCancelledException();