Merge pull request #234 from LukeOwncloud/develop
[pub/Android/ownCloud.git] / src / com / owncloud / android / datamodel / FileDataStorageManager.java
index d84eb2a..f461193 100644 (file)
@@ -235,6 +235,12 @@ public class FileDataStorageManager implements DataStorageManager {
             if (fileExists(file.getRemotePath())) {
                 OCFile oldFile = getFileByPath(file.getRemotePath());
                 file.setFileId(oldFile.getFileId());
             if (fileExists(file.getRemotePath())) {
                 OCFile oldFile = getFileByPath(file.getRemotePath());
                 file.setFileId(oldFile.getFileId());
+               
+                if (file.isDirectory()) {
+                    cv.put(ProviderTableMeta.FILE_CONTENT_LENGTH, oldFile.getFileLength());
+                    file.setFileLength(oldFile.getFileLength());
+                }
+                
                 operations.add(ContentProviderOperation.newUpdate(ProviderTableMeta.CONTENT_URI).
                         withValues(cv).
                         withSelection(  ProviderTableMeta._ID + "=?", 
                 operations.add(ContentProviderOperation.newUpdate(ProviderTableMeta.CONTENT_URI).
                         withValues(cv).
                         withSelection(  ProviderTableMeta._ID + "=?", 
@@ -245,9 +251,14 @@ public class FileDataStorageManager implements DataStorageManager {
                 OCFile oldFile = getFileById(file.getFileId());
                 if (file.getStoragePath() == null && oldFile.getStoragePath() != null)
                     file.setStoragePath(oldFile.getStoragePath());
                 OCFile oldFile = getFileById(file.getFileId());
                 if (file.getStoragePath() == null && oldFile.getStoragePath() != null)
                     file.setStoragePath(oldFile.getStoragePath());
-                if (!file.isDirectory());
-                cv.put(ProviderTableMeta.FILE_STORAGE_PATH, file.getStoragePath());
-
+                
+                if (!file.isDirectory())
+                    cv.put(ProviderTableMeta.FILE_STORAGE_PATH, file.getStoragePath());
+                else {
+                    cv.put(ProviderTableMeta.FILE_CONTENT_LENGTH, oldFile.getFileLength());
+                    file.setFileLength(oldFile.getFileLength());
+                }
+                
                 operations.add(ContentProviderOperation.newUpdate(ProviderTableMeta.CONTENT_URI).
                         withValues(cv).
                         withSelection(  ProviderTableMeta._ID + "=?", 
                 operations.add(ContentProviderOperation.newUpdate(ProviderTableMeta.CONTENT_URI).
                         withValues(cv).
                         withSelection(  ProviderTableMeta._ID + "=?", 
@@ -546,16 +557,16 @@ public class FileDataStorageManager implements DataStorageManager {
                 try {
                     c = getContentProvider().query(ProviderTableMeta.CONTENT_URI, 
                             null,
                 try {
                     c = getContentProvider().query(ProviderTableMeta.CONTENT_URI, 
                             null,
-                            ProviderTableMeta.FILE_ACCOUNT_OWNER + "=? AND " + ProviderTableMeta.FILE_PATH + " LIKE ?",
-                            new String[] { mAccount.name, dir.getRemotePath() + "%" }, null);
+                            ProviderTableMeta.FILE_ACCOUNT_OWNER + "=? AND " + ProviderTableMeta.FILE_PATH + " LIKE ? ",
+                            new String[] { mAccount.name, dir.getRemotePath() + "%"  }, ProviderTableMeta.FILE_PATH + " ASC ");
                 } catch (RemoteException e) {
                     Log_OC.e(TAG, e.getMessage());
                 }
             } else {
                 c = getContentResolver().query(ProviderTableMeta.CONTENT_URI, 
                         null,
                 } catch (RemoteException e) {
                     Log_OC.e(TAG, e.getMessage());
                 }
             } else {
                 c = getContentResolver().query(ProviderTableMeta.CONTENT_URI, 
                         null,
-                        ProviderTableMeta.FILE_ACCOUNT_OWNER + "=? AND " + ProviderTableMeta.FILE_PATH + " LIKE ?",
-                        new String[] { mAccount.name, dir.getRemotePath() + "%" }, null);
+                        ProviderTableMeta.FILE_ACCOUNT_OWNER + "=? AND " + ProviderTableMeta.FILE_PATH + " LIKE ? ",
+                        new String[] { mAccount.name, dir.getRemotePath() + "%"  }, ProviderTableMeta.FILE_PATH + " ASC ");
             }
 
             /// 2. prepare a batch of update operations to change all the descendants
             }
 
             /// 2. prepare a batch of update operations to change all the descendants