Skip to content

Commit 06ac6df

Browse files
fantessileht
authored andcommitted
fix: replace db":true by db":false in json files when copying models
1 parent 30fb2ca commit 06ac6df

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/backends/caffe/caffemodel.cc

+4
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,10 @@ namespace dd
212212
{
213213
std::vector<std::string> selts = dd_utils::split((*hit), '/');
214214
fileops::copy_file((*hit), target_repo + '/' + selts.back());
215+
if (selts.back().find(".json") != std::string::npos)
216+
fileops::replace_string_in_file(target_repo + '/'
217+
+ selts.back(),
218+
"db\":true", "db\":false");
215219
}
216220
++hit;
217221
}

src/utils/fileops.hpp

+26
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,32 @@ namespace dd
286286
return 0;
287287
}
288288

289+
static int replace_string_in_file(const std::string &filename,
290+
const std::string &search,
291+
const std::string &replace)
292+
{
293+
int nr = 0;
294+
std::ifstream ifs(filename.c_str(),
295+
std::ios::in | std::ios::binary | std::ios::ate);
296+
std::stringstream sstr;
297+
sstr << ifs.rdbuf();
298+
ifs.close();
299+
std::string filestring = sstr.str();
300+
301+
size_t pos = 0;
302+
while ((pos = filestring.find(search, pos)) != std::string::npos)
303+
{
304+
filestring.replace(pos, search.length(), replace);
305+
pos += replace.length();
306+
nr++;
307+
}
308+
std::ofstream out(filename.c_str(),
309+
std::ios::out | std::ios::binary | std::ios::trunc);
310+
out << filestring;
311+
out.close();
312+
return nr;
313+
}
314+
289315
static int copy_uncompressed_data(struct archive *ar, struct archive *aw)
290316
{
291317
int r;

0 commit comments

Comments
 (0)