diff --git a/src/com/owncloud/android/operations/SynchronizeFolderOperation.java b/src/com/owncloud/android/operations/SynchronizeFolderOperation.java index 3671ca0eb3..d2e45a43cf 100644 --- a/src/com/owncloud/android/operations/SynchronizeFolderOperation.java +++ b/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); diff --git a/src/com/owncloud/android/operations/UploadFileOperation.java b/src/com/owncloud/android/operations/UploadFileOperation.java index fc9da4b8a1..9c570ea056 100644 --- a/src/com/owncloud/android/operations/UploadFileOperation.java +++ b/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 diff --git a/src/com/owncloud/android/ui/activity/UploadFilesActivity.java b/src/com/owncloud/android/ui/activity/UploadFilesActivity.java index 84c89593ea..516781c122 100644 --- a/src/com/owncloud/android/ui/activity/UploadFilesActivity.java +++ b/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); } /** diff --git a/src/com/owncloud/android/utils/FileStorageUtils.java b/src/com/owncloud/android/utils/FileStorageUtils.java index 620e581e82..63aee6b5ce 100644 --- a/src/com/owncloud/android/utils/FileStorageUtils.java +++ b/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(); + } + + } } \ No newline at end of file