int ACTIVE_TASK::copy_output_files() { for (size_t i = 0; i < result->output_files.size(); ++i) { FILE_REF& fref = result->output_files[i]; if (!fref.copy_file) { continue; } const FILE_INFO* fip = fref.file_info; std::string slotfile = slot_dir + std::string("/") + std::string(fref.open_name); std::string projfile = get_pathname(fip); int retval = boinc_rename(slotfile.c_str(), projfile.c_str()); if (retval) { msg_printf(wup->project, MSG_INTERNAL_ERROR, "Can't rename output file %s to %s: %s", fip->name.c_str(), projfile.c_str(), boincerror(retval)); } } return 0; }
void DAILY_XFER_HISTORY::write_state() { FILE* f = fopen(TEMP_FILE_NAME, "w"); if (!f) return; fprintf(f, "<daily_xfers>\n"); for (unsigned int i=0; i<daily_xfers.size(); i++) { DAILY_XFER& dx = daily_xfers[i]; dx.write(f); } int n = fprintf(f, "</daily_xfers>\n"); fclose(f); if (n > 0) { int retval = boinc_rename(TEMP_FILE_NAME, DAILY_XFER_HISTORY_FILENAME); if (!retval) { dirty = false; } } }
void GET_PROJECT_LIST_OP::handle_reply(int http_op_retval) { bool error = false; if (http_op_retval) { error_num = http_op_retval; error = true; } else { string s; read_file_string(ALL_PROJECTS_LIST_FILENAME_TEMP, s); if (strstr(s.c_str(), "</projects>")) { boinc_rename( ALL_PROJECTS_LIST_FILENAME_TEMP, ALL_PROJECTS_LIST_FILENAME ); gstate.all_projects_list_check_time = gstate.now; } else { error = true; } } // if error, try again in a day // if (error) { gstate.all_projects_list_check_time = gstate.now - ALL_PROJECTS_LIST_CHECK_PERIOD + SECONDS_PER_DAY; } }
// Write the client_state.xml file // int CLIENT_STATE::write_state_file() { MFILE mf; int retval, ret1, ret2, attempt; #ifdef _WIN32 char win_error_msg[4096]; #endif for (attempt=1; attempt<=MAX_STATE_FILE_WRITE_ATTEMPTS; attempt++) { if (attempt > 1) boinc_sleep(1.0); if (log_flags.statefile_debug) { msg_printf(0, MSG_INFO, "[statefile] Writing state file" ); } #ifdef _WIN32 retval = mf.open(STATE_FILE_NEXT, "wc"); #else retval = mf.open(STATE_FILE_NEXT, "w"); #endif if (retval) { if ((attempt == MAX_STATE_FILE_WRITE_ATTEMPTS) || log_flags.statefile_debug) { msg_printf(0, MSG_INTERNAL_ERROR, "Can't open %s: %s", STATE_FILE_NEXT, boincerror(retval) ); } if (attempt < MAX_STATE_FILE_WRITE_ATTEMPTS) continue; return ERR_FOPEN; } MIOFILE miof; miof.init_mfile(&mf); ret1 = write_state(miof); ret2 = mf.close(); if (ret1) { if ((attempt == MAX_STATE_FILE_WRITE_ATTEMPTS) || log_flags.statefile_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; } // 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)) { retval = boinc_delete_file(STATE_FILE_PREV); if (retval) { if ((attempt == MAX_STATE_FILE_WRITE_ATTEMPTS) || log_flags.statefile_debug) { #ifdef _WIN32 msg_printf(0, MSG_INFO, "Can't delete previous state file; %s", windows_format_error_string(GetLastError(), win_error_msg, sizeof(win_error_msg)) ); #else msg_printf(0, MSG_INFO, "Can't delete previous state file: %s", strerror(errno) ); #endif } if (attempt < MAX_STATE_FILE_WRITE_ATTEMPTS) continue; } } retval = boinc_rename(STATE_FILE_NAME, STATE_FILE_PREV); if (retval) { if ((attempt == MAX_STATE_FILE_WRITE_ATTEMPTS) || log_flags.statefile_debug) { #ifdef _WIN32 msg_printf(0, MSG_INFO, "Can't rename current state file to previous state file; %s", windows_format_error_string(GetLastError(), win_error_msg, sizeof(win_error_msg)) ); #else msg_printf(0, MSG_INFO, "Can't rename current state file to previous state file: %s", strerror(errno) ); #endif } if (attempt < MAX_STATE_FILE_WRITE_ATTEMPTS) continue; } } retval = boinc_rename(STATE_FILE_NEXT, STATE_FILE_NAME); if (log_flags.statefile_debug) { msg_printf(0, MSG_INFO, "[statefile] Done writing state file" ); } if (!retval) break; // Success! if ((attempt == MAX_STATE_FILE_WRITE_ATTEMPTS) || log_flags.statefile_debug) { #ifdef _WIN32 msg_printf(0, MSG_INFO, "rename error: %s", windows_format_error_string(GetLastError(), win_error_msg, sizeof(win_error_msg)) ); #elif defined (__APPLE__) if (log_flags.statefile_debug) { system("ls -al /Library/Application\\ Support/BOINC\\ Data/client*.*"); } #endif } if (attempt < MAX_STATE_FILE_WRITE_ATTEMPTS) continue; return ERR_RENAME; } return 0; }