MCPcopy Create free account
hub / github.com/MaxBelkov/visualsyslog / RotateFile

Method RotateFile

source/fdb.cpp:153–242  ·  view source on GitHub ↗

---------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

151}
152//---------------------------------------------------------------------------
153void 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();

Callers 1

CheckRotateMethod · 0.80

Calls 6

PreRotateFileFunction · 0.85
WriteToLogErrorFunction · 0.85
FormatLastError2Function · 0.85
PostRotateFileFunction · 0.85
InsertMethod · 0.80
CloseMethod · 0.45

Tested by

no test coverage detected