// 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 // Program to install files as part of auto-update. // Run in a directory that contains the new files. // Arguments: // // --install_dir X copy files to X (required) // --run_manager when done, run Manager // --run_as_service when done, run core client as service // // What it does: // 1) wait for a mutex, to ensure that the core client has exited // 2) create or empty out a "previous-version" dir // 3) copy files from install dir to previous-version dir // 4) copy files from current dir to install dir // 5) run the new core client and/or manager // // If we get an error in 2) or 3): // 6) run the (old) core client and/or manager // We pass it a "--run_from_updater" option; this causes it to // mark the update as failed, so it won't try again. // If we get an error in 4) or 5): // 7) copy files from previous-version dir back to install dir // 8) run the old core client and/or manager #include #ifdef _WIN32 #else #include #include #endif #include #include "filesys.h" #include "util.h" using std::vector; #ifdef _WIN32 #define CORE_NAME "boinc.exe" #define MANAGER_NAME "boincmgr.exe" #else #define CORE_NAME "boinc_client" #define MANAGER_NAME "boinc_mgr" #endif char* install_dir; char prev_dir[1024]; int prepare_prev_dir() { int retval; if (is_dir(prev_dir)) { retval = clean_out_dir(prev_dir); if (retval) return retval; } else { retval = boinc_mkdir(prev_dir); if (retval) return retval; } return 0; } int move_file(char* file, char* old_dir, char* new_dir) { char old_path[1024], new_path[1024]; sprintf(old_path, "%s/%s", old_dir, file); sprintf(new_path, "%s/%s", new_dir, file); int retval = boinc_rename(old_path, new_path); fprintf(stderr, "rename %s to %s\n", old_path, new_path); if (retval) { fprintf(stderr, "couldn't rename %s to %s\n", old_path, new_path); } return retval; } // try to move all; return 0 if moved all // int move_files(vector files, char* old_dir, char* new_dir) { int retval = 0; for (unsigned int i=0; i files; install_dir = 0; for (i=1; i