Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1135,15 +1135,16 @@ public static String getTimestampedFileName(final String extension) {
/**
* @return -1 if no space could computed, otherwise available space in bytes
*/
public static Long getAvailableSpaceOnDevice() {
StatFs stat;
public static long getAvailableSpaceOnDevice() {
try {
stat = new StatFs(MainApp.getStoragePath());
} catch (NullPointerException | IllegalArgumentException e) {
StatFs statFs = new StatFs(Environment.getDataDirectory().getPath());
long availableBlocks = statFs.getAvailableBlocksLong();
long blockSize = statFs.getBlockSizeLong();
return availableBlocks * blockSize;
} catch (Exception e) {
Log_OC.e(TAG, "getAvailableSpaceOnDevice: " + e);
return -1L;
}

return stat.getBlockSizeLong() * stat.getAvailableBlocksLong();
}

public static boolean isEndToEndEncryptionSetup(Context context, User user) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -787,14 +787,13 @@ private static boolean canListFiles(File f) {
*
* @param file @link{OCFile}
* @return boolean: true if there is enough space left
* @throws RuntimeException
*/
public static boolean checkIfEnoughSpace(OCFile file) {
// Get the remaining space on device
long availableSpaceOnDevice = FileOperationsHelper.getAvailableSpaceOnDevice();

if (availableSpaceOnDevice == -1) {
throw new RuntimeException("Error while computing available space");
return false;
}

return checkIfEnoughSpace(availableSpaceOnDevice, file);
Expand Down
Loading