Skip to content

Commit

Permalink
cats: convert first element to number or return zero in case of error
Browse files Browse the repository at this point in the history
- adds a bit more readability to the code
  • Loading branch information
franku authored and joergsteffens committed Sep 24, 2020
1 parent 9e83658 commit 909948c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
8 changes: 8 additions & 0 deletions core/src/cats/cats.h
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,14 @@ class db_list_ctx : public BStringList {
void add(JobId_t id) { push_back(std::to_string(id)); }

std::string GetAsString() { return Join(','); }
uint64_t GetFrontAsInteger()
{
try {
return std::stoull(at(0));
} catch (...) {
return 0;
}
}
};

typedef enum
Expand Down
2 changes: 1 addition & 1 deletion core/src/dird/backup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ bool SendAccurateCurrentFiles(JobControlRecord* jcr)
jcr->file_bsock->fsend("accurate files=%s\n", nb.GetAsString().c_str());

if (jcr->HasBase) {
jcr->nb_base_files = str_to_int64(nb.GetAsString().c_str());
jcr->nb_base_files = nb.GetFrontAsInteger();
if (!jcr->db->CreateBaseFileList(jcr, jobids.GetAsString().c_str())) {
Jmsg(jcr, M_FATAL, 0, "error in jcr->db->CreateBaseFileList:%s\n",
jcr->db->strerror());
Expand Down
13 changes: 13 additions & 0 deletions core/src/tests/test_db_list_ctx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,16 @@ TEST(db_list_ctx, list)
EXPECT_TRUE(bstrcmp(list1.GetAsString().c_str(), "11,12,13"));
EXPECT_STREQ(list1.GetAsString().c_str(), "11,12,13");
}

TEST(db_list_ctx, GetFrontAsInteger)
{
db_list_ctx nb;

EXPECT_EQ(0, nb.GetFrontAsInteger());

nb.add(11);
EXPECT_EQ(11, nb.GetFrontAsInteger());

nb.add(12);
EXPECT_EQ(11, nb.GetFrontAsInteger());
}

0 comments on commit 909948c

Please sign in to comment.