Client: Rework write_state_file logic to always retry on error, suppress intermediate warnings

svn path=/trunk/boinc/; revision=14893
This commit is contained in:
Charlie Fenton 2008-03-11 12:55:33 +00:00
parent 68ee073311
commit b5e838b00e
1 changed files with 59 additions and 78 deletions

View File

@ -498,31 +498,26 @@ int CLIENT_STATE::write_state_file() {
miof.init_mfile(&mf);
ret1 = write_state(miof);
ret2 = mf.close();
if ((!ret1) && (!ret2)) break;
if (ret1) {
if ((attempt == MAX_STATE_FILE_WRITE_ATTEMPTS) || log_flags.state_debug) {
msg_printf(NULL, MSG_INTERNAL_ERROR,
"Couldn't write state file: %s", boincerror(retval)
);
}
if (attempt < MAX_STATE_FILE_WRITE_ATTEMPTS) continue;
return ret1;
}
if (ret2) {
if (attempt < MAX_STATE_FILE_WRITE_ATTEMPTS) continue;
return ret2;
}
break;
}
for (attempt=1; attempt<=MAX_STATE_FILE_WRITE_ATTEMPTS; attempt++) {
if (attempt > 1) boinc_sleep(1.0);
if (ret1) return ret1;
if (ret2) return ret2;
// only attempt to rename the current state file if it exists.
//
if (boinc_file_exists(STATE_FILE_NAME)) {
if (boinc_file_exists(STATE_FILE_PREV)) {
for (attempt=1; attempt<=MAX_STATE_FILE_WRITE_ATTEMPTS; attempt++) {
if (attempt > 1) boinc_sleep(1.0);
retval = boinc_delete_file(STATE_FILE_PREV);
if (retval) {
if (!retval) break;
if ((attempt == MAX_STATE_FILE_WRITE_ATTEMPTS) || log_flags.state_debug) {
#ifdef _WIN32
msg_printf(0, MSG_USER_ERROR,
@ -536,19 +531,13 @@ int CLIENT_STATE::write_state_file() {
);
#endif
}
if (attempt < MAX_STATE_FILE_WRITE_ATTEMPTS) continue;
}
}
}
break;
}
for (attempt=1; attempt<=MAX_STATE_FILE_WRITE_ATTEMPTS; attempt++) {
if (attempt > 1) boinc_sleep(1.0);
if (boinc_file_exists(STATE_FILE_NAME)) {
retval = boinc_rename(STATE_FILE_NAME, STATE_FILE_PREV);
if (retval) {
if (!retval) break;
if ((attempt == MAX_STATE_FILE_WRITE_ATTEMPTS) || log_flags.state_debug) {
#ifdef _WIN32
msg_printf(0, MSG_USER_ERROR,
@ -562,22 +551,18 @@ int CLIENT_STATE::write_state_file() {
);
#endif
}
if (attempt < MAX_STATE_FILE_WRITE_ATTEMPTS) continue;
}
}
break;
}
for (attempt=1; attempt<=MAX_STATE_FILE_WRITE_ATTEMPTS; attempt++) {
if (attempt > 1) boinc_sleep(1.0);
retval = boinc_rename(STATE_FILE_NEXT, STATE_FILE_NAME);
if (log_flags.state_debug) {
msg_printf(0, MSG_INFO,
"[status_debug] CLIENT_STATE::write_state_file(): Done writing state file"
);
}
if (retval) {
if (!retval) return 0;
if ((attempt == MAX_STATE_FILE_WRITE_ATTEMPTS) || log_flags.state_debug) {
#ifdef _WIN32
if (retval == ERROR_ACCESS_DENIED) {
@ -606,13 +591,9 @@ int CLIENT_STATE::write_state_file() {
);
#endif
}
if (attempt < MAX_STATE_FILE_WRITE_ATTEMPTS) continue;
}
return ERR_RENAME;
}
break;
}
return 0;
}
int CLIENT_STATE::write_state(MIOFILE& f) {
unsigned int i, j;