Skip to content

Commit

Permalink
fix: replace db":true by db":false in json files when copying models
Browse files Browse the repository at this point in the history
  • Loading branch information
fantes authored and sileht committed Sep 18, 2020
1 parent 30fb2ca commit 06ac6df
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/backends/caffe/caffemodel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,10 @@ namespace dd
{
std::vector<std::string> selts = dd_utils::split((*hit), '/');
fileops::copy_file((*hit), target_repo + '/' + selts.back());
if (selts.back().find(".json") != std::string::npos)
fileops::replace_string_in_file(target_repo + '/'
+ selts.back(),
"db\":true", "db\":false");
}
++hit;
}
Expand Down
26 changes: 26 additions & 0 deletions src/utils/fileops.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,32 @@ namespace dd
return 0;
}

static int replace_string_in_file(const std::string &filename,
const std::string &search,
const std::string &replace)
{
int nr = 0;
std::ifstream ifs(filename.c_str(),
std::ios::in | std::ios::binary | std::ios::ate);
std::stringstream sstr;
sstr << ifs.rdbuf();
ifs.close();
std::string filestring = sstr.str();

size_t pos = 0;
while ((pos = filestring.find(search, pos)) != std::string::npos)
{
filestring.replace(pos, search.length(), replace);
pos += replace.length();
nr++;
}
std::ofstream out(filename.c_str(),
std::ios::out | std::ios::binary | std::ios::trunc);
out << filestring;
out.close();
return nr;
}

static int copy_uncompressed_data(struct archive *ar, struct archive *aw)
{
int r;
Expand Down

0 comments on commit 06ac6df

Please sign in to comment.