Replace the upgradefluxfile builtin with a seperate upgrade-flux-file tool.

This allows us to remove all the SQL stuff from the main program, and restores
the ability to upgrade from version 2 SQL files.
This commit is contained in:
David Given
2022-02-04 21:27:24 +01:00
parent 091ef6d972
commit 89688394f8
23 changed files with 334 additions and 479 deletions

View File

@@ -53,10 +53,8 @@ std::unique_ptr<FluxSource> FluxSource::createFl2FluxSource(const Fl2FluxSourceP
char buffer[16];
std::ifstream(config.filename(), std::ios::in | std::ios::binary).read(buffer, 16);
if (strncmp(buffer, "SQLite format 3", 16) == 0)
{
std::cerr << "Warning: reading a deprecated flux file format; please upgrade it\n";
return FluxSource::createSqliteFluxSource(config.filename());
}
Error() << "this flux file is too old; please use the upgrade-flux-file to upgrade it";
return std::unique_ptr<FluxSource>(new Fl2FluxSource(config));
}

View File

@@ -18,9 +18,6 @@ std::unique_ptr<FluxSource> FluxSource::create(const FluxSourceProto& config)
{
switch (config.source_case())
{
case FluxSourceProto::kFluxfile:
return createSqliteFluxSource(config.fluxfile());
case FluxSourceProto::kDrive:
return createHardwareFluxSource(config.drive());

View File

@@ -26,7 +26,6 @@ private:
static std::unique_ptr<FluxSource> createHardwareFluxSource(const HardwareFluxSourceProto& config);
static std::unique_ptr<FluxSource> createKryofluxFluxSource(const KryofluxFluxSourceProto& config);
static std::unique_ptr<FluxSource> createScpFluxSource(const ScpFluxSourceProto& config);
static std::unique_ptr<FluxSource> createSqliteFluxSource(const std::string& filename);
static std::unique_ptr<FluxSource> createTestPatternFluxSource(const TestPatternFluxSourceProto& config);
public:

View File

@@ -41,7 +41,6 @@ message Fl2FluxSourceProto {
message FluxSourceProto {
optional double rescale = 9 [ default = 1.0, (help) = "amount to divide pulse periods by" ];
oneof source {
string fluxfile = 1 [default = "name of source flux file"];
HardwareFluxSourceProto drive = 2;
TestPatternFluxSourceProto test_pattern = 3;
EraseFluxSourceProto erase = 4;

View File

@@ -1,42 +0,0 @@
#include "globals.h"
#include "fluxmap.h"
#include "sql.h"
#include "fluxsource/fluxsource.h"
#include "fmt/format.h"
class SqliteFluxSource : public FluxSource
{
public:
SqliteFluxSource(const std::string& filename)
{
_indb = sqlOpen(filename, SQLITE_OPEN_READONLY);
int version = sqlGetVersion(_indb);
if (version != FLUX_VERSION_CURRENT)
Error() << fmt::format("that flux file is version {}, but this client is for version {}",
version, FLUX_VERSION_CURRENT);
}
~SqliteFluxSource()
{
if (_indb)
sqlClose(_indb);
}
public:
std::unique_ptr<Fluxmap> readFlux(int track, int side)
{
return sqlReadFlux(_indb, track, side);
}
void recalibrate() {}
private:
sqlite3* _indb;
};
std::unique_ptr<FluxSource> FluxSource::createSqliteFluxSource(const std::string& filename)
{
return std::unique_ptr<FluxSource>(new SqliteFluxSource(filename));
}