| 105 | } |
| 106 | |
| 107 | bool FileOpsImpl::FileRotate |
| 108 | ( |
| 109 | const string _filename |
| 110 | ) |
| 111 | { |
| 112 | int i = 1; |
| 113 | string newFile; |
| 114 | /* find a filename not used yet */ |
| 115 | newFile = _filename; |
| 116 | newFile.append(".").append(intToString(i)); |
| 117 | while (FileExists(newFile)) { |
| 118 | i++; |
| 119 | newFile = _filename; |
| 120 | newFile.append(".").append(intToString(i)); |
| 121 | } |
| 122 | /* copy the file */ |
| 123 | if (!FileCopy(_filename, newFile)) { |
| 124 | Log::Write(LogLevel_Warning, "File Rotate Failed: %s -> %s", _filename.c_str(), newFile.c_str()); |
| 125 | return false; |
| 126 | } |
| 127 | |
| 128 | /* remove the old file */ |
| 129 | if ( remove(_filename.c_str())) { |
| 130 | Log::Write(LogLevel_Warning, "File Removal failed: %s", _filename.c_str()); |
| 131 | return false; |
| 132 | } |
| 133 | return true; |
| 134 | } |
| 135 | |
| 136 | |
| 137 | bool FileOpsImpl::FileCopy |