Fix MakeDisk utility

This addresses two issues: (1) failing to check for regular files;
(2) failing to test for files larger than 2GB.

(issue #44)
This commit is contained in:
Andy McFadden 2020-11-07 09:17:14 -08:00
parent 9de0b42147
commit 7c637c4e6d

View File

@ -13,6 +13,8 @@
#include <time.h>
#include <errno.h>
#include <assert.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "../diskimg/DiskImg.h"
using namespace DiskImgLib;
@ -97,7 +99,21 @@ CopyFiles(DiskFS* pDiskFS, int argc, char** argv)
};
argv--;
while (argc--) {
argv++;
// Confirm this is a regular file, and not a directory.
struct stat sb;
if (stat(*argv, &sb) != 0) {
fprintf(stderr, "Warning: unable to stat '%s'\n", *argv);
continue;
}
if ((sb.st_mode & S_IFREG) == 0) {
printf("--- Skipping '%s'\n", *argv);
continue;
}
printf("+++ Adding '%s'\n", *argv);
/*
@ -148,6 +164,11 @@ CopyFiles(DiskFS* pDiskFS, int argc, char** argv)
}
len = ftell(fp);
if (len >= 1L<<31) { // 2GB
fprintf(stderr, "Warning: file '%s' too large, skipping\n", *argv);
fclose(fp);
continue;
}
rewind(fp);
buf = new char[len];
@ -199,11 +220,6 @@ CopyFiles(DiskFS* pDiskFS, int argc, char** argv)
pNewFile->GetPathName(), DIStrError(dierr));
return -1;
}
/*
* On to the next file.
*/
argv++;
}
return 0;