mirror of
https://github.com/nextcloud/android.git
synced 2024-11-27 17:46:37 +03:00
Fixed lack of File#getUsableSpace() in Android versions previous to GINGERBREAD
This commit is contained in:
parent
4558866223
commit
8361540852
4 changed files with 16 additions and 7 deletions
|
@ -296,11 +296,10 @@ public class SynchronizeFolderOperation extends RemoteOperation {
|
||||||
private void checkAndFixForeignStoragePath(OCFile file) {
|
private void checkAndFixForeignStoragePath(OCFile file) {
|
||||||
String storagePath = file.getStoragePath();
|
String storagePath = file.getStoragePath();
|
||||||
String expectedPath = FileStorageUtils.getDefaultSavePathFor(mAccount.name, file);
|
String expectedPath = FileStorageUtils.getDefaultSavePathFor(mAccount.name, file);
|
||||||
File ocLocalFolder = new File(FileStorageUtils.getSavePath(mAccount.name));
|
|
||||||
if (storagePath != null && !storagePath.equals(expectedPath)) {
|
if (storagePath != null && !storagePath.equals(expectedPath)) {
|
||||||
/// fix storagePaths out of the local ownCloud folder
|
/// fix storagePaths out of the local ownCloud folder
|
||||||
File originalFile = new File(storagePath);
|
File originalFile = new File(storagePath);
|
||||||
if (ocLocalFolder.getUsableSpace() < originalFile.length()) {
|
if (FileStorageUtils.getUsableSpace(mAccount.name) < originalFile.length()) {
|
||||||
mForgottenLocalFiles.put(file.getRemotePath(), storagePath);
|
mForgottenLocalFiles.put(file.getRemotePath(), storagePath);
|
||||||
file.setStoragePath(null);
|
file.setStoragePath(null);
|
||||||
|
|
||||||
|
|
|
@ -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)
|
/// 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) {
|
if (!originalStoragePath.equals(expectedPath) && mLocalBehaviour == FileUploader.LOCAL_BEHAVIOUR_COPY) {
|
||||||
|
|
||||||
File ocLocalFolder = new File(FileStorageUtils.getSavePath(mAccount.name));
|
if (FileStorageUtils.getUsableSpace(mAccount.name) < originalFile.length()) {
|
||||||
if (ocLocalFolder.getUsableSpace() < originalFile.length()) {
|
|
||||||
result = new RemoteOperationResult(ResultCode.LOCAL_STORAGE_FULL);
|
result = new RemoteOperationResult(ResultCode.LOCAL_STORAGE_FULL);
|
||||||
return result; // error condition when the file should be copied
|
return result; // error condition when the file should be copied
|
||||||
|
|
||||||
|
|
|
@ -319,9 +319,7 @@ public class UploadFilesActivity extends SherlockFragmentActivity implements
|
||||||
File localFile = new File(localPath);
|
File localFile = new File(localPath);
|
||||||
total += localFile.length();
|
total += localFile.length();
|
||||||
}
|
}
|
||||||
String savePath = FileStorageUtils.getSavePath(mAccount.name);
|
return (FileStorageUtils.getUsableSpace(mAccount.name) >= total);
|
||||||
File saveDir = new File(savePath);
|
|
||||||
return (saveDir.getUsableSpace() >= total);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -22,6 +22,8 @@ import java.io.File;
|
||||||
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
|
import android.os.StatFs;
|
||||||
|
|
||||||
import com.owncloud.android.datamodel.OCFile;
|
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
|
// 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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in a new issue