Browse Source

Fixed lack of File#getUsableSpace() in Android versions previous to GINGERBREAD

David A. Velasco 12 years ago
parent
commit
8361540852

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

@@ -296,11 +296,10 @@ public class SynchronizeFolderOperation extends RemoteOperation {
     private void checkAndFixForeignStoragePath(OCFile file) {
         String storagePath = file.getStoragePath();
         String expectedPath = FileStorageUtils.getDefaultSavePathFor(mAccount.name, file);
-        File ocLocalFolder = new File(FileStorageUtils.getSavePath(mAccount.name));
         if (storagePath != null && !storagePath.equals(expectedPath)) {
             /// fix storagePaths out of the local ownCloud folder
             File originalFile = new File(storagePath);
-            if (ocLocalFolder.getUsableSpace() < originalFile.length()) {
+            if (FileStorageUtils.getUsableSpace(mAccount.name) < originalFile.length()) {
                 mForgottenLocalFiles.put(file.getRemotePath(), storagePath);
                 file.setStoragePath(null);
                     

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

@@ -166,8 +166,7 @@ public class UploadFileOperation extends RemoteOperation {
             /// check location of local file; if not the expected, copy to a temporal file before upload (if COPY is the expected behaviour)
             if (!originalStoragePath.equals(expectedPath) && mLocalBehaviour == FileUploader.LOCAL_BEHAVIOUR_COPY) {
 
-                File ocLocalFolder = new File(FileStorageUtils.getSavePath(mAccount.name));
-                if (ocLocalFolder.getUsableSpace() < originalFile.length()) {
+                if (FileStorageUtils.getUsableSpace(mAccount.name) < originalFile.length()) {
                     result = new RemoteOperationResult(ResultCode.LOCAL_STORAGE_FULL);
                     return result;  // error condition when the file should be copied
                         

+ 1 - 3
src/com/owncloud/android/ui/activity/UploadFilesActivity.java

@@ -319,9 +319,7 @@ public class UploadFilesActivity extends SherlockFragmentActivity implements
                 File localFile = new File(localPath);
                 total += localFile.length();
             }
-            String savePath = FileStorageUtils.getSavePath(mAccount.name);
-            File saveDir = new File(savePath);
-            return (saveDir.getUsableSpace() >= total);
+            return (FileStorageUtils.getUsableSpace(mAccount.name) >= total);
         }
 
         /**

+ 13 - 0
src/com/owncloud/android/utils/FileStorageUtils.java

@@ -22,6 +22,8 @@ import java.io.File;
 
 import android.net.Uri;
 import android.os.Environment;
+import android.os.StatFs;
+
 import com.owncloud.android.datamodel.OCFile;
 
 
@@ -43,5 +45,16 @@ public class FileStorageUtils {
             // URL encoding is an 'easy fix' to overcome that NTFS and FAT32 don't allow ":" in file names, that can be in the accountName since 0.1.190B
     }
 
+    public static final long getUsableSpace(String accountName) {
+        File savePath = Environment.getExternalStorageDirectory();
+        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.GINGERBREAD) {
+            return savePath.getUsableSpace();
+            
+        } else {
+            StatFs stats = new StatFs(savePath.getAbsolutePath());
+            return stats.getAvailableBlocks() * stats.getBlockSize();
+        }
+        
+    }
     
 }