MCPcopy Create free account
hub / github.com/OpenFOAM/OpenFOAM-dev / mvBak

Function mvBak

src/OSspecific/POSIX/POSIX.C:942–981  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

940
941
942bool Foam::mvBak(const fileName& src, const std::string& ext)
943{
944 if (POSIX::debug)
945 {
946 //InfoInFunction
947 Pout<< FUNCTION_NAME
948 << " : moving : " << src << " to extension " << ext << endl;
949 if ((POSIX::debug & 2) && !Pstream::master())
950 {
951 error::printStack(Pout);
952 }
953 }
954
955 if (exists(src, false))
956 {
957 const int maxIndex = 99;
958 char index[3];
959
960 for (int n = 0; n <= maxIndex; n++)
961 {
962 fileName dstName(src + "." + ext);
963 if (n)
964 {
965 sprintf(index, "%02d", n);
966 dstName += index;
967 }
968
969 // avoid overwriting existing files, except for the last
970 // possible index where we have no choice
971 if (!exists(dstName, false) || n == maxIndex)
972 {
973 return ::rename(src.c_str(), dstName.c_str()) == 0;
974 }
975
976 }
977 }
978
979 // fall-through: nothing to do
980 return false;
981}
982
983
984bool Foam::rm(const fileName& file)

Callers 6

mainFunction · 0.50
mainFunction · 0.50
rewriteBoundaryFunction · 0.50
rewriteFieldFunction · 0.50
forAllConstIterFunction · 0.50
forAllConstIterFunction · 0.50

Calls 3

printStackFunction · 0.70
existsFunction · 0.70
renameFunction · 0.50

Tested by 2

mainFunction · 0.40
mainFunction · 0.40