Skip to content

Commit

Permalink
Merge pull request #239 from bareos/dev/franku/master/bugfixes
Browse files Browse the repository at this point in the history
- source-addr-test
- fileregexp-test
  • Loading branch information
franku committed Aug 13, 2019
2 parents 12f6412 + 04d5916 commit 20a8f26
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 30 deletions.
83 changes: 55 additions & 28 deletions core/src/dird/bsr.cc
Expand Up @@ -511,41 +511,43 @@ void PrintBsr(UaContext* ua, RestoreContext& rx)
fprintf(stdout, "%s", buffer.c_str());
}

/**
* Find the right bsr for the supplied jobid, creating it if it doesn't yet
* exist.
*/
static RestoreBootstrapRecord* GetBsrForJobId(RestoreBootstrapRecord* bsr,
JobId_t t_JobId)
{
if (bsr->fi->Empty()) { /* if no FI yet, jobid is not yet set */
bsr->JobId = t_JobId;
return bsr;
}
if (bsr->JobId != t_JobId) {
auto found = false;
do {
if (!bsr->next.get()) {
bsr->next = std::make_unique<RestoreBootstrapRecord>(t_JobId);
found = true;
} else if (bsr->next.get()->JobId == t_JobId) {
found = true;
}
bsr = bsr->next.get();
} while (!found);
}
return bsr;
}

/**
* Add a FileIndex to the list of BootStrap records.
* Here we are only dealing with JobId's and the FileIndexes
* associated with those JobIds.
*/
void AddFindex(RestoreBootstrapRecord* bsr, uint32_t JobId, int32_t findex)
{
RestoreBootstrapRecord* nbsr;

if (findex == 0) { return; /* probably a dummy directory */ }
GetBsrForJobId(bsr, JobId)->fi->Add(findex);

if (bsr->fi->Empty()) { /* if no FI yet, jobid is not yet set */
bsr->JobId = JobId;
}

/*
* Walk down list of bsrs until we find the JobId
*/
if (bsr->JobId != JobId) {
for (nbsr = bsr->next.get(); nbsr; nbsr = nbsr->next.get()) {
if (nbsr->JobId == JobId) {
bsr = nbsr;
break;
}
}

if (!nbsr) { /* Must add new JobId */
/*
* Add new JobId at end of chain
*/
for (nbsr = bsr; nbsr->next.get(); nbsr = nbsr->next.get()) {}
nbsr->next = std::make_unique<RestoreBootstrapRecord>(JobId);
bsr = nbsr->next.get();
}
}

bsr->fi->Add(findex);
}

/**
Expand All @@ -555,7 +557,32 @@ void AddFindex(RestoreBootstrapRecord* bsr, uint32_t JobId, int32_t findex)
*/
void AddFindexAll(RestoreBootstrapRecord* bsr, uint32_t JobId)
{
GetBsrForJobId(bsr, JobId)->fi->AddAll();
RestoreBootstrapRecord* nbsr;

if (bsr->fi->Empty()) { /* if no FI add one */
bsr->JobId = JobId;
}

/*
* Walk down list of bsrs until we find the JobId
*/
if (bsr->JobId != JobId) {
for (nbsr = bsr->next.get(); nbsr; nbsr = nbsr->next.get()) {
if (nbsr->JobId == JobId) {
bsr = nbsr;
break;
}
}

if (!nbsr) { /* Must add new JobId */
for (nbsr = bsr; nbsr->next.get(); nbsr = nbsr->next.get()) {}
nbsr->next = std::make_unique<RestoreBootstrapRecord>(JobId);
if (bsr->fileregex) { nbsr->next->fileregex = strdup(bsr->fileregex); }
bsr = nbsr->next.get();
}
}

bsr->fi->AddAll();
}

/**
Expand Down
4 changes: 2 additions & 2 deletions regress/tests/source-addr-test
Expand Up @@ -55,8 +55,8 @@ if [ $os = 'FreeBSD' ]; then
INTERFACE=xn0
IP=`ifconfig ${INTERFACE} | perl -ne '/inet (.+?) / && print $1'`
elif [ $os = 'Linux' ]; then
INTERFACE=eth0
IP=`ifconfig ${INTERFACE} | perl -ne '/inet addr:(.+?) / && print $1'`
INTERFACE=$(ip addr show | awk '/inet.*brd/{print $NF; exit}')
IP=$(ip addr show | awk '/inet.*brd/{print $2; exit}' | sed 's,\(\w\+\)/.*,\1,')
fi

if [ "$IP" = '' ]; then
Expand Down

0 comments on commit 20a8f26

Please sign in to comment.