Skip to content

Commit

Permalink
Merge pull request #6909 from nextcloud/backport/6900/stable-3.13
Browse files Browse the repository at this point in the history
[stable-3.13] Fix npe on computing enough space with non-downloaded folder content
  • Loading branch information
AndyScherzinger authored Sep 8, 2020
2 parents 0593279 + 0728872 commit 21e48a5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -392,9 +392,24 @@ class OCFileListFragmentIT : AbstractOnServerIT() {
assertTrue(sut.checkIfEnoughSpace(200L, ocFile))

ocFile.fileLength = 100
assertFalse(sut.checkIfEnoughSpace(50L, ocFile))

ocFile.fileLength = 44
assertTrue(sut.checkIfEnoughSpace(50L, ocFile))

ocFile.fileLength = 100
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))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
import com.owncloud.android.utils.DisplayUtils;
import com.owncloud.android.utils.EncryptionUtils;
import com.owncloud.android.utils.FileSortOrder;
import com.owncloud.android.utils.FileStorageUtils;
import com.owncloud.android.utils.MimeTypeUtil;
import com.owncloud.android.utils.ThemeUtils;

Expand Down Expand Up @@ -1775,13 +1776,22 @@ private void syncAndCheckFiles(Collection<OCFile> files) {
public boolean checkIfEnoughSpace(long availableSpaceOnDevice, OCFile file) {
if (file.isFolder()) {
// 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 {
// on files complete file must first be stored, then target gets overwritten
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) {
SyncFileNotEnoughSpaceDialogFragment dialog =
SyncFileNotEnoughSpaceDialogFragment.newInstance(file, availableSpaceOnDevice);
Expand Down

0 comments on commit 21e48a5

Please sign in to comment.