Получение полного списка снимков
This commit is contained in:
parent
9ba43b0e38
commit
e42aacbed7
4 changed files with 18 additions and 26 deletions
|
@ -3,16 +3,11 @@ module cdcdb.cdc.cas;
|
||||||
import cdcdb.db;
|
import cdcdb.db;
|
||||||
import cdcdb.cdc.core;
|
import cdcdb.cdc.core;
|
||||||
|
|
||||||
import std.digest.sha : SHA256, digest;
|
|
||||||
import std.format : format;
|
|
||||||
|
|
||||||
import zstd;
|
import zstd;
|
||||||
|
|
||||||
|
import std.digest.sha : SHA256, digest;
|
||||||
|
import std.format : format;
|
||||||
import std.exception : enforce;
|
import std.exception : enforce;
|
||||||
import std.stdio : writeln;
|
|
||||||
import std.conv : to;
|
|
||||||
|
|
||||||
import std.file : write;
|
|
||||||
|
|
||||||
// Content-Addressable Storage (Контентно-адресуемая система хранения)
|
// Content-Addressable Storage (Контентно-адресуемая система хранения)
|
||||||
// CAS-хранилище со снапшотами
|
// CAS-хранилище со снапшотами
|
||||||
|
@ -54,6 +49,10 @@ public:
|
||||||
|
|
||||||
size_t newSnapshot(string label, const(ubyte)[] data, string description = string.init)
|
size_t newSnapshot(string label, const(ubyte)[] data, string description = string.init)
|
||||||
{
|
{
|
||||||
|
if (data.length == 0) {
|
||||||
|
throw new Exception("Данные имеют нулевой размер");
|
||||||
|
}
|
||||||
|
|
||||||
ubyte[32] sha256 = digest!SHA256(data);
|
ubyte[32] sha256 = digest!SHA256(data);
|
||||||
|
|
||||||
// Если последний снимок файла соответствует текущему состоянию
|
// Если последний снимок файла соответствует текущему состоянию
|
||||||
|
@ -132,9 +131,9 @@ public:
|
||||||
return idSnapshot;
|
return idSnapshot;
|
||||||
}
|
}
|
||||||
|
|
||||||
Snapshot[] getSnapshotList(string filePath)
|
Snapshot[] getSnapshots(string label = "")
|
||||||
{
|
{
|
||||||
return _db.getSnapshots(filePath);
|
return _db.getSnapshots(label);
|
||||||
}
|
}
|
||||||
|
|
||||||
ubyte[] getSnapshotData(const ref Snapshot snapshot)
|
ubyte[] getSnapshotData(const ref Snapshot snapshot)
|
||||||
|
|
|
@ -8,13 +8,3 @@ struct Chunk
|
||||||
size_t size; // размер чанка
|
size_t size; // размер чанка
|
||||||
ubyte[32] sha256; // hex(SHA-256) содержимого
|
ubyte[32] sha256; // hex(SHA-256) содержимого
|
||||||
}
|
}
|
||||||
|
|
||||||
// Метаданные снимка
|
|
||||||
struct SnapshotInfo
|
|
||||||
{
|
|
||||||
size_t id;
|
|
||||||
string createdUTC; // ISO-8601
|
|
||||||
string label;
|
|
||||||
size_t sourceLength;
|
|
||||||
size_t chunks;
|
|
||||||
}
|
|
||||||
|
|
|
@ -4,7 +4,6 @@ import cdcdb.db.types;
|
||||||
|
|
||||||
import arsd.sqlite;
|
import arsd.sqlite;
|
||||||
|
|
||||||
import std.file : exists;
|
|
||||||
import std.exception : enforce;
|
import std.exception : enforce;
|
||||||
import std.conv : to;
|
import std.conv : to;
|
||||||
import std.string : join, replace, toLower;
|
import std.string : join, replace, toLower;
|
||||||
|
@ -151,9 +150,11 @@ public:
|
||||||
snapshot.status.to!int
|
snapshot.status.to!int
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!queryResult.empty())
|
if (queryResult.empty()) {
|
||||||
|
throw new Exception("Ошибка при добавлении нового снимока в базу данных");
|
||||||
|
}
|
||||||
|
|
||||||
return queryResult.front()["id"].to!long;
|
return queryResult.front()["id"].to!long;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void addBlob(Blob blob)
|
void addBlob(Blob blob)
|
||||||
|
@ -211,7 +212,7 @@ public:
|
||||||
q{
|
q{
|
||||||
SELECT id, label, sha256, description, created_utc, source_length,
|
SELECT id, label, sha256, description, created_utc, source_length,
|
||||||
algo_min, algo_normal, algo_max, mask_s, mask_l, status
|
algo_min, algo_normal, algo_max, mask_s, mask_l, status
|
||||||
FROM snapshots WHERE label = ?
|
FROM snapshots WHERE (length(?) = 0 OR label = ?1);
|
||||||
}, label
|
}, label
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -7,10 +7,12 @@ import std.file : read;
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
auto cas = new CAS("/tmp/base.db", true);
|
auto cas = new CAS("/tmp/base.db", true);
|
||||||
cas.newSnapshot("/tmp/text", cast(ubyte[]) read("/tmp/text"));
|
cas.newSnapshot("/tmp/texts", cast(ubyte[]) read("/tmp/text"));
|
||||||
// import std.stdio : writeln;
|
// import std.stdio : writeln;
|
||||||
|
|
||||||
writeln(cas.getSnapshotList("/tmp/text"));
|
foreach (snapshot; cas.getSnapshots()) {
|
||||||
|
writeln(snapshot);
|
||||||
|
}
|
||||||
|
|
||||||
// writeln(cas.getVersion);
|
// writeln(cas.getVersion);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue