Skip to content

Commit

Permalink
hardlink: make better use of C++ features
Browse files Browse the repository at this point in the history
  • Loading branch information
sebsura authored and BareosBot committed Sep 22, 2023
1 parent c7f1272 commit 7114742
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
25 changes: 14 additions & 11 deletions core/src/findlib/hardlink.cc
Expand Up @@ -47,15 +47,9 @@ CurLink* new_hardlink(LinkHash*& table, char* fname, ino_t ino, dev_t dev)
{
if (!table) { table = new LinkHash(10000); }

auto [iter, inserted] = table->try_emplace(Hardlink{dev, ino});
auto [iter, inserted] = table->try_emplace(Hardlink{dev, ino}, fname);
if (!inserted) { return nullptr; }
CurLink& hl = iter->second;
hl.name.assign(fname);

hl.digest_stream = 0; /* Set later */
hl.FileIndex = 0; /* Set later */

return &hl;
return &iter->second;
}

/**
Expand All @@ -67,8 +61,17 @@ void FfPktSetLinkDigest(CurLink* link,
const char* digest,
uint32_t len)
{
if (link && link->digest.empty()) { /* is a hardlink */
link->digest = std::vector(digest, digest + len);
link->digest_stream = digest_stream;
if (link) { /* is a hardlink */
link->set_digest(digest_stream, digest, len);
}
}

void CurLink::set_digest(int32_t new_digest_stream,
const char* new_digest,
uint32_t len)
{
if (digest.empty()) {
digest.assign(new_digest, new_digest + len);
digest_stream = new_digest_stream;
}
}
12 changes: 7 additions & 5 deletions core/src/findlib/hardlink.h
Expand Up @@ -34,11 +34,13 @@
* entry so we can link it.
*/
struct CurLink {
struct hlink link;
uint32_t FileIndex; /**< Bareos FileIndex of this file */
int32_t digest_stream; /**< Digest type if needed */
std::vector<char> digest; /**< Checksum of the file if needed */
std::string name; /**< The name */
uint32_t FileIndex{0}; /**< Bareos FileIndex of this file */
int32_t digest_stream{0}; /**< Digest type if needed */
std::vector<char> digest{}; /**< Checksum of the file if needed */
std::string name; /**< The name */

CurLink(const char* fname) : name{fname} {}
void set_digest(int32_t digest_stream, const char* digest, uint32_t len);
};

struct Hardlink {
Expand Down

0 comments on commit 7114742

Please sign in to comment.