Merge pull request #619 from davidgiven/b602

Fix weird error when trying to create fatfs filesystems.
This commit is contained in:
David Given
2022-11-27 12:33:33 +01:00
committed by GitHub
4 changed files with 13 additions and 3 deletions

View File

@@ -3,6 +3,7 @@
#include "lib/bytes.h"
#include <fmt/format.h>
#include <iomanip>
#include <fstream>
bool emergencyStop = false;
@@ -190,3 +191,10 @@ std::string tohex(const std::string& s)
return ss.str();
}
bool doesFileExist(const std::string& filename)
{
std::ifstream f(filename);
return f.good();
}

View File

@@ -18,6 +18,7 @@ extern std::string toIso8601(time_t t);
extern std::string quote(const std::string& s);
extern std::string unhex(const std::string& s);
extern std::string tohex(const std::string& s);
extern bool doesFileExist(const std::string& filename);
/* If set, any running job will terminate as soon as possible (with an error).
*/

View File

@@ -246,11 +246,11 @@ public:
switch (cmd)
{
case GET_SECTOR_SIZE:
*(DWORD*)buffer = getLogicalSectorSize();
*(WORD*)buffer = getLogicalSectorSize();
break;
case GET_SECTOR_COUNT:
*(DWORD*)buffer = getLogicalSectorCount();
*(LBA_t*)buffer = getLogicalSectorCount();
break;
case CTRL_SYNC:

View File

@@ -235,7 +235,8 @@ std::unique_ptr<Filesystem> Filesystem::createFilesystemFromConfig()
{
std::shared_ptr<ImageReader> reader;
std::shared_ptr<ImageWriter> writer;
if (config.image_reader().type() != ImageReaderProto::NOT_SET)
if ((config.image_reader().type() != ImageReaderProto::NOT_SET) &&
doesFileExist(config.image_reader().filename()))
reader = ImageReader::create(config.image_reader());
if (config.image_writer().type() != ImageWriterProto::NOT_SET)
writer = ImageWriter::create(config.image_writer());