| 940 | |
| 941 | |
| 942 | bool 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 | |
| 984 | bool Foam::rm(const fileName& file) |