Add safety checks for low SD card space (#90)

* Some attempt.

* Enable some-safety-freespace-work nightlies

* Upload elf with nightly

* *Derp fixes.*

* Bye Bye testing things.

* Revert "Upload elf with nightly"

This reverts commit 303968cd78e466a3fcc010915565d8265acaa76a.

* Add safety checks to fcopy

Co-authored-by: StackZ <47382115+SuperSaiyajinStackZ@users.noreply.github.com>
This commit is contained in:
Pk11
2021-05-26 05:47:51 -05:00
committed by GitHub
parent bfecbc86af
commit baa14561eb
11 changed files with 150 additions and 110 deletions
+15 -1
View File
@@ -25,6 +25,7 @@
*/
#include "fileBrowse.hpp"
#include "files.hpp"
#include "json.hpp"
#include "structs.hpp"
#include <3ds.h>
@@ -236,6 +237,11 @@ int fcopy(const char *sourcePath, const char *destinationPath) {
return -1;
}
if(getAvailableSpace() < copySize) {
fclose(sourceFile);
return -1;
}
FILE *destinationFile = fopen(destinationPath, "wb");
if (!destinationFile) {
fclose(sourceFile);
@@ -245,7 +251,15 @@ int fcopy(const char *sourcePath, const char *destinationPath) {
while(1) {
/* Copy file to destination path. */
int numr = fread(copyBuf, sizeof(u32), copyBufSize, sourceFile);
fwrite(copyBuf, sizeof(u32), numr, destinationFile);
int written = fwrite(copyBuf, sizeof(u32), numr, destinationFile);
if(written != numr) {
fclose(sourceFile);
fclose(destinationFile);
return -1;
}
copyOffset += copyBufSize * sizeof(u32);
if (copyOffset > copySize) {