Skip to content

Commit

Permalink
Merge pull request #602 from bareos/dev/joergs/master/config-dump-fix
Browse files Browse the repository at this point in the history
Fixes newly introduced problems with the show command
  • Loading branch information
joergsteffens committed Sep 17, 2020
2 parents d90f438 + fb38828 commit ff2fd7b
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 34 deletions.
6 changes: 2 additions & 4 deletions core/src/dird/dird_conf.cc
Expand Up @@ -2134,8 +2134,7 @@ bool FilesetResource::PrintConfig(

Dmsg0(200, "FilesetResource::PrintConfig\n");

send.ResourceTypeStart("FileSets");
send.ResourceStart(this->resource_name_);
send.ResourceStart("FileSets", "FileSet", this->resource_name_);
send.KeyQuotedString("Name", this->resource_name_);

if (this->description_ != NULL) {
Expand Down Expand Up @@ -2208,8 +2207,7 @@ bool FilesetResource::PrintConfig(
send.ArrayEnd("Exclude", inherited, "");
}

send.ResourceEnd(this->resource_name_);
send.ResourceTypeEnd("FileSet");
send.ResourceEnd("FileSets", "FileSet", this->resource_name_);

return true;
}
Expand Down
36 changes: 20 additions & 16 deletions core/src/lib/output_formatter_resource.cc
Expand Up @@ -82,28 +82,32 @@ std::string OutputFormatterResource::GetKeyFormatString(bool inherited,
return format;
}

void OutputFormatterResource::ResourceTypeStart(const char* name,
bool as_comment)
void OutputFormatterResource::ResourceStart(const char* resource_type_groupname,
const char* resource_type_name,
const char* resource_name,
bool as_comment)
{
send_->ObjectStart(name, GetKeyFormatString(as_comment, "%s {\n").c_str());
const bool case_sensitive_name = true;
/*
* Use resource_type_groupname as structure key (JSON),
* but use resource_type_name when writing config resources.
*/
std::string format = std::string(resource_type_name) + std::string(" {\n");
send_->ObjectStart(resource_type_groupname,
GetKeyFormatString(as_comment, format).c_str());
indent_level_++;
send_->ObjectStart(resource_name, nullptr, case_sensitive_name);
}

void OutputFormatterResource::ResourceTypeEnd(const char* name, bool as_comment)
void OutputFormatterResource::ResourceEnd(const char* resource_type_groupname,
const char* resource_type_name,
const char* resource_name,
bool as_comment)
{
send_->ObjectEnd(resource_name);
indent_level_--;
send_->ObjectEnd(name, GetKeyFormatString(as_comment, "}\n\n").c_str());
}

void OutputFormatterResource::ResourceStart(const char* name)
{
const bool case_sensitive_name = true;
send_->ObjectStart(name, nullptr, case_sensitive_name);
}

void OutputFormatterResource::ResourceEnd(const char* name)
{
send_->ObjectEnd(name);
send_->ObjectEnd(resource_type_groupname,
GetKeyFormatString(as_comment, "}\n\n").c_str());
}

void OutputFormatterResource::SubResourceStart(const char* name,
Expand Down
13 changes: 8 additions & 5 deletions core/src/lib/output_formatter_resource.h
Expand Up @@ -64,11 +64,14 @@ class OutputFormatterResource {
std::string GetKeyFormatString(bool inherited,
std::string baseformat = "%s = ");

void ResourceTypeStart(const char* name, bool as_comment = false);
void ResourceTypeEnd(const char* name, bool as_comment = false);

void ResourceStart(const char* name);
void ResourceEnd(const char* name);
void ResourceStart(const char* resource_type_groupname,
const char* resource_type_name,
const char* resource_name,
bool as_comment = false);
void ResourceEnd(const char* resource_type_groupname,
const char* resource_type_name,
const char* resource_name,
bool as_comment = false);

void SubResourceStart(const char* name,
bool as_comment = false,
Expand Down
14 changes: 6 additions & 8 deletions core/src/lib/res.cc
Expand Up @@ -1671,8 +1671,7 @@ bool MessagesResource::PrintConfig(OutputFormatterResource& send,

msgres = this;

send.ResourceTypeStart("Messages");
send.ResourceStart(resource_name_);
send.ResourceStart("Messages", "Messages", resource_name_);

send.KeyQuotedString("Name", resource_name_);

Expand Down Expand Up @@ -1715,8 +1714,7 @@ bool MessagesResource::PrintConfig(OutputFormatterResource& send,
}
}

send.ResourceEnd(resource_name_);
send.ResourceTypeEnd("Messages");
send.ResourceEnd("Messages", "Messages", resource_name_);

return true;
}
Expand Down Expand Up @@ -2130,8 +2128,8 @@ bool BareosResource::PrintConfig(OutputFormatterResource& send,

*my_config.resources_[rindex].allocated_resource_ = this;

send.ResourceTypeStart(my_config.ResGroupToStr(rcode_), internal_);
send.ResourceStart(resource_name_);
send.ResourceStart(my_config.ResGroupToStr(rcode_),
my_config.ResToStr(rcode_), resource_name_, internal_);

for (int i = 0; items[i].name; i++) {
bool inherited = BitIsSet(i, inherit_content_);
Expand All @@ -2140,8 +2138,8 @@ bool BareosResource::PrintConfig(OutputFormatterResource& send,
verbose);
}

send.ResourceEnd(resource_name_);
send.ResourceTypeEnd(my_config.ResToStr(rcode_), internal_);
send.ResourceEnd(my_config.ResGroupToStr(rcode_), my_config.ResToStr(rcode_),
resource_name_, internal_);

return true;
}
Expand Down
2 changes: 1 addition & 1 deletion systemtests/tests/python-bareos/python-bareos-unittest.py
Expand Up @@ -1499,7 +1499,7 @@ def test_fileset(self):
fileset_content_list = result["filesets"][0]["filesettext"]

result = director.call("show fileset={}".format(fileset))
fileset_show_description = result["fileset"][fileset]["description"]
fileset_show_description = result["filesets"][fileset]["description"]

self.assertIn(fileset_show_description, fileset_content_list)

Expand Down

0 comments on commit ff2fd7b

Please sign in to comment.