MCPcopy Create free account
hub / github.com/apache/brpc / GetUniquePathNumber

Function GetUniquePathNumber

src/butil/file_util.cc:249–267  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

247}
248
249int GetUniquePathNumber(const FilePath& path,
250 const FilePath::StringType& suffix) {
251 bool have_suffix = !suffix.empty();
252 if (!PathExists(path) &&
253 (!have_suffix || !PathExists(FilePath(path.value() + suffix)))) {
254 return 0;
255 }
256
257 FilePath new_path;
258 for (int count = 1; count <= kMaxUniqueFiles; ++count) {
259 new_path = path.InsertBeforeExtensionASCII(StringPrintf(" (%d)", count));
260 if (!PathExists(new_path) &&
261 (!have_suffix || !PathExists(FilePath(new_path.value() + suffix)))) {
262 return count;
263 }
264 }
265
266 return -1;
267}
268
269} // namespace butil

Callers

nothing calls this directly

Calls 6

PathExistsFunction · 0.85
StringPrintfFunction · 0.85
FilePathClass · 0.50
emptyMethod · 0.45
valueMethod · 0.45

Tested by

no test coverage detected