// Berkeley Open Infrastructure for Network Computing // http://boinc.berkeley.edu // Copyright (C) 2006 University of California // // This is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; // either version 2.1 of the License, or (at your option) any later version. // // This software is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. // See the GNU Lesser General Public License for more details. // // To view the GNU Lesser General Public License visit // http://www.gnu.org/copyleft/lesser.html // or write to the Free Software Foundation, Inc., // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #include "parse.h" #include "error_numbers.h" #include "filesys.h" #include "client_msgs.h" #include "file_names.h" #include "client_state.h" #include "log_flags.h" #include "auto_update.h" // while an update is being downloaded, // it's treated like other project files, // except that a version directory is prepended to filenames. // // When the download is complete, // the version directory is moved to the top level dir. AUTO_UPDATE::AUTO_UPDATE() { present = false; } int AUTO_UPDATE::parse(MIOFILE& in) { char buf[256]; int retval; while (in.fgets(buf, 256)) { if (match_tag(buf, "")) { return 0; } else if (match_tag(buf, "")) { version.parse(in); } else if (match_tag(buf, "")) { FILE_REF fref; retval = fref.parse(in); if (retval) return retval; file_refs.push_back(fref); } else { if (log_flags.unparsed_xml) { msg_printf(NULL, MSG_INFO, "unparsed in boinc_update: %s", buf); } } } return ERR_XML_PARSE; } void AUTO_UPDATE::write(MIOFILE& out) { out.printf( "\n" ); version.write(out); for (unsigned int i=0; i\n" ); } // a scheduler reply included an . Deal with it. // void AUTO_UPDATE::handle_in_reply(PROJECT* proj) { char dir[256], buf[256]; int retval; if (gstate.auto_update.present) { if (!version.greater_than(gstate.auto_update.version)) { msg_printf(NULL, MSG_INFO, "Got request to updated to %d.%d.%d; already updating to %d.%d.%d", version.major, version.minor, version.release, gstate.auto_update.version.major, gstate.auto_update.version.minor, gstate.auto_update.version.release ); return; } // TODO: abort in-progress update (and delete files) here } project = proj; // create version directory and prepend to file names // boinc_version_dir(version, dir); retval = boinc_mkdir(dir); if (retval) return; gstate.auto_update = *this; for (unsigned int i=0; iname); } } void AUTO_UPDATE::install() { msg_printf(NULL, MSG_INFO, "Installing new version: %d.%d.%d", version.major, version.minor, version.release ); } void AUTO_UPDATE::poll() { if (!present) return; static double last_time = 0; if (gstate.now - last_time < 10) return; last_time = gstate.now; for (unsigned int i=0; istatus != FILE_PRESENT) return; } install(); } int VERSION_INFO::parse(MIOFILE& in) { char buf[256]; while (in.fgets(buf, 256)) { if (match_tag(buf, "")) return 0; if (parse_int(buf, "", major)) continue; if (parse_int(buf, "", minor)) continue; if (parse_int(buf, "", release)) continue; } return ERR_XML_PARSE; } void VERSION_INFO::write(MIOFILE& out) { out.printf( "\n" " %d\n" " %d\n" " %d\n" "\n", major, minor, release ); } bool VERSION_INFO::greater_than(VERSION_INFO& vi) { if (major > vi.major) return true; if (major < vi.major) return false; if (minor > vi.minor) return true; if (minor < vi.minor) return false; if (release > vi.release) return true; return false; }