MCPcopy Create free account
hub / github.com/audacity/audacity / SafetyFileName

Method SafetyFileName

libraries/lib-project-file-io/ProjectFileIO.cpp:1252–1285  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1250}
1251
1252FilePath ProjectFileIO::SafetyFileName(const FilePath &src)
1253{
1254 wxFileNameWrapper fn{ src };
1255
1256 // Extra characters inserted into filename before extension
1257 wxString extra =
1258#ifdef __WXGTK__
1259 wxT("~")
1260#else
1261 wxT(".bak")
1262#endif
1263 ;
1264
1265 int nn = 1;
1266 auto numberString = [](int num) -> wxString {
1267 return num == 1 ? wxString{} : wxString::Format(".%d", num);
1268 };
1269
1270 auto suffixes = AuxiliaryFileSuffixes();
1271 suffixes.push_back({});
1272
1273 // Find backup paths not already occupied; check all auxiliary suffixes
1274 const auto name = fn.GetName();
1275 FilePath result;
1276 do {
1277 fn.SetName( name + numberString(nn++) + extra );
1278 result = fn.GetFullPath();
1279 }
1280 while( std::any_of(suffixes.begin(), suffixes.end(), [&](auto &suffix){
1281 return wxFileExists(result + suffix);
1282 }) );
1283
1284 return result;
1285}
1286
1287bool ProjectFileIO::RenameOrWarn(const FilePath &src, const FilePath &dst)
1288{

Callers

nothing calls this directly

Calls 5

push_backMethod · 0.45
GetNameMethod · 0.45
SetNameMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected