mirror of
https://github.com/nextcloud/android.git
synced 2024-11-25 06:35:48 +03:00
Merge pull request #6900 from nextcloud/fixCheckIfEnoughSpace
Fix npe on computing enough space with non-downloaded folder content
This commit is contained in:
commit
fdeca7c5a2
2 changed files with 26 additions and 1 deletions
|
@ -392,9 +392,24 @@ class OCFileListFragmentIT : AbstractOnServerIT() {
|
||||||
assertTrue(sut.checkIfEnoughSpace(200L, ocFile))
|
assertTrue(sut.checkIfEnoughSpace(200L, ocFile))
|
||||||
|
|
||||||
ocFile.fileLength = 100
|
ocFile.fileLength = 100
|
||||||
|
assertFalse(sut.checkIfEnoughSpace(50L, ocFile))
|
||||||
|
|
||||||
|
ocFile.fileLength = 44
|
||||||
assertTrue(sut.checkIfEnoughSpace(50L, ocFile))
|
assertTrue(sut.checkIfEnoughSpace(50L, ocFile))
|
||||||
|
|
||||||
ocFile.fileLength = 100
|
ocFile.fileLength = 100
|
||||||
assertTrue(sut.checkIfEnoughSpace(100L, ocFile))
|
assertTrue(sut.checkIfEnoughSpace(100L, ocFile))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@SuppressWarnings("MagicNumber")
|
||||||
|
fun testEnoughSpaceWithNoLocalFolder() {
|
||||||
|
val sut = OCFileListFragment()
|
||||||
|
val ocFile = OCFile("/test/")
|
||||||
|
|
||||||
|
ocFile.mimeType = "DIR"
|
||||||
|
|
||||||
|
ocFile.fileLength = 100
|
||||||
|
assertTrue(sut.checkIfEnoughSpace(200L, ocFile))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,6 +100,7 @@ import com.owncloud.android.ui.preview.PreviewTextFileFragment;
|
||||||
import com.owncloud.android.utils.DisplayUtils;
|
import com.owncloud.android.utils.DisplayUtils;
|
||||||
import com.owncloud.android.utils.EncryptionUtils;
|
import com.owncloud.android.utils.EncryptionUtils;
|
||||||
import com.owncloud.android.utils.FileSortOrder;
|
import com.owncloud.android.utils.FileSortOrder;
|
||||||
|
import com.owncloud.android.utils.FileStorageUtils;
|
||||||
import com.owncloud.android.utils.MimeTypeUtil;
|
import com.owncloud.android.utils.MimeTypeUtil;
|
||||||
import com.owncloud.android.utils.ThemeUtils;
|
import com.owncloud.android.utils.ThemeUtils;
|
||||||
|
|
||||||
|
@ -1782,13 +1783,22 @@ public class OCFileListFragment extends ExtendedListFragment implements
|
||||||
public boolean checkIfEnoughSpace(long availableSpaceOnDevice, OCFile file) {
|
public boolean checkIfEnoughSpace(long availableSpaceOnDevice, OCFile file) {
|
||||||
if (file.isFolder()) {
|
if (file.isFolder()) {
|
||||||
// on folders we assume that we only need difference
|
// on folders we assume that we only need difference
|
||||||
return availableSpaceOnDevice > (file.getFileLength() - new File(file.getStoragePath()).length());
|
return availableSpaceOnDevice > (file.getFileLength() - localFolderSize(file));
|
||||||
} else {
|
} else {
|
||||||
// on files complete file must first be stored, then target gets overwritten
|
// on files complete file must first be stored, then target gets overwritten
|
||||||
return availableSpaceOnDevice > file.getFileLength();
|
return availableSpaceOnDevice > file.getFileLength();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private long localFolderSize(OCFile file) {
|
||||||
|
if (file.getStoragePath() == null) {
|
||||||
|
// not yet downloaded anything
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
return FileStorageUtils.getFolderSize(new File(file.getStoragePath()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void showSpaceErrorDialog(OCFile file, long availableSpaceOnDevice) {
|
private void showSpaceErrorDialog(OCFile file, long availableSpaceOnDevice) {
|
||||||
SyncFileNotEnoughSpaceDialogFragment dialog =
|
SyncFileNotEnoughSpaceDialogFragment dialog =
|
||||||
SyncFileNotEnoughSpaceDialogFragment.newInstance(file, availableSpaceOnDevice);
|
SyncFileNotEnoughSpaceDialogFragment.newInstance(file, availableSpaceOnDevice);
|
||||||
|
|
Loading…
Reference in a new issue