---------------------------------------------------------------------------
| 151 | } |
| 152 | //--------------------------------------------------------------------------- |
| 153 | void TStorageFile::RotateFile(void) |
| 154 | { |
| 155 | out.Close(); // close current writing file |
| 156 | |
| 157 | if( IsNeedRenameAfterRotate() ) |
| 158 | { |
| 159 | // rename file to rotation_name |
| 160 | |
| 161 | String f = GetFileName(); |
| 162 | String n = GetNewRotationName(); |
| 163 | |
| 164 | PreRotateFile(f); // close current viewed file |
| 165 | PreRotateFile(n); |
| 166 | |
| 167 | if( ! ::MoveFileEx(f.c_str(), n.c_str(), |
| 168 | MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH) ) |
| 169 | { |
| 170 | DWORD e = GetLastError(); |
| 171 | if( e!=2 ) // ignore error: "can't find file" |
| 172 | WriteToLogError("ERROR\tRotate file from \"%s\" to \"%s\": %s [%lu]", |
| 173 | f.c_str(), n.c_str(), FormatLastError2(e).c_str(), e); |
| 174 | } |
| 175 | else |
| 176 | { |
| 177 | String file_to_delete; |
| 178 | RotationLogAddItem(n, file_to_delete); |
| 179 | if( ! file_to_delete.IsEmpty() ) |
| 180 | if( ! DeleteFile(file_to_delete) ) |
| 181 | { |
| 182 | DWORD e = GetLastError(); |
| 183 | WriteToLogError("ERROR\tDelete old rotated file \"%s\": %s [%lu]", |
| 184 | file_to_delete.c_str(), FormatLastError2(e).c_str(), e); |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | PostRotateFile(); // open current viewed file if been closed |
| 189 | } |
| 190 | else |
| 191 | { |
| 192 | // rename file to file+number[rotation_count] |
| 193 | |
| 194 | // rotation log open |
| 195 | TStringList * p = new TStringList; |
| 196 | String rlf = RotationLogFormatFileName(); |
| 197 | //try { p->LoadFromFile(rlf); } catch(...) {} |
| 198 | |
| 199 | for(int i=rotation_count-1; i>=0; i--) |
| 200 | { |
| 201 | String f = GetFileNameToRotate(i); |
| 202 | String n = GetFileNameToRotate(i+1); |
| 203 | |
| 204 | PreRotateFile(f); // close current viewed file |
| 205 | PreRotateFile(n); |
| 206 | |
| 207 | if( ! ::MoveFileEx(f.c_str(), n.c_str(), |
| 208 | MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH) ) |
| 209 | { |
| 210 | DWORD e = GetLastError(); |
no test coverage detected