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);
/// 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
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);
}
/**
import android.net.Uri;
import android.os.Environment;
+import android.os.StatFs;
+
import com.owncloud.android.datamodel.OCFile;
// 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