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

This commit is contained in:
David A. Velasco 2012-12-04 14:36:49 +01:00
parent 4558866223
commit 8361540852
4 changed files with 16 additions and 7 deletions

View file

@ -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);

View file

@ -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

View file

@ -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);
}
/**

View file

@ -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();
}
}
}