From 64d7fa34744c87392c6845d1d6c8adbf802d0cfa Mon Sep 17 00:00:00 2001 From: David Anderson Date: Thu, 18 Apr 2013 13:57:33 -0700 Subject: [PATCH] - client: more fixes to GUI RPC addition. Also, replace get_project_dir() with a memoized member function of PROJECT --- client/app.cpp | 5 ++--- client/app_config.cpp | 5 ++--- client/app_start.cpp | 9 ++------- client/cs_account.cpp | 5 ++--- client/cs_prefs.cpp | 5 ++--- client/cs_statefile.cpp | 5 ++--- client/cs_trickle.cpp | 16 +++++++--------- client/file_names.cpp | 30 ++++++++++-------------------- client/file_names.h | 1 - client/project.cpp | 33 +++++++++++++++++++++++---------- client/project.h | 5 +++++ 11 files changed, 57 insertions(+), 62 deletions(-) diff --git a/client/app.cpp b/client/app.cpp index 4c71d92416..314d74ed9b 100644 --- a/client/app.cpp +++ b/client/app.cpp @@ -420,14 +420,13 @@ void ACTIVE_TASK_SET::get_memory_usage() { // Move it from slot dir to project dir // int ACTIVE_TASK::move_trickle_file() { - char project_dir[MAXPATHLEN], new_path[MAXPATHLEN], old_path[MAXPATHLEN]; + char new_path[MAXPATHLEN], old_path[MAXPATHLEN]; int retval; - get_project_dir(result->project, project_dir, sizeof(project_dir)); sprintf(old_path, "%s/trickle_up.xml", slot_dir); sprintf(new_path, "%s/trickle_up_%s_%d.xml", - project_dir, result->name, (int)time(0) + result->project->project_dir(), result->name, (int)time(0) ); retval = boinc_rename(old_path, new_path); diff --git a/client/app_config.cpp b/client/app_config.cpp index 1043179385..747f2a6525 100644 --- a/client/app_config.cpp +++ b/client/app_config.cpp @@ -118,13 +118,12 @@ void max_concurrent_init() { } void check_app_config() { - char dir[256], path[MAXPATHLEN]; + char path[MAXPATHLEN]; FILE* f; for (unsigned int i=0; iproject_dir(), APP_CONFIG_FILE_NAME); f = boinc_fopen(path, "r"); if (!f) continue; msg_printf(p, MSG_INFO, diff --git a/client/app_start.cpp b/client/app_start.cpp index 00c657eb51..fd080e4bfb 100644 --- a/client/app_start.cpp +++ b/client/app_start.cpp @@ -193,8 +193,6 @@ int ACTIVE_TASK::get_shmem_seg_name() { } void ACTIVE_TASK::init_app_init_data(APP_INIT_DATA& aid) { - char project_dir[256], project_path[MAXPATHLEN]; - aid.major_version = BOINC_MAJOR_VERSION; aid.minor_version = BOINC_MINOR_VERSION; aid.release = BOINC_RELEASE; @@ -212,9 +210,7 @@ void ACTIVE_TASK::init_app_init_data(APP_INIT_DATA& aid) { aid.hostid = wup->project->hostid; safe_strcpy(aid.user_name, wup->project->user_name); safe_strcpy(aid.team_name, wup->project->team_name); - get_project_dir(wup->project, project_dir, sizeof(project_dir)); - relative_to_absolute(project_dir, project_path); - strcpy(aid.project_dir, project_path); + strcpy(aid.project_dir, wup->project->project_dir_absolute()); relative_to_absolute("", aid.boinc_dir); strcpy(aid.authenticator, wup->project->authenticator); aid.slot = slot; @@ -941,8 +937,7 @@ int ACTIVE_TASK::start() { // char libpath[8192]; char newlibs[256]; - get_project_dir(wup->project, buf, sizeof(buf)); - sprintf(newlibs, "../../%s:.:../..", buf); + sprintf(newlibs, "../../%s:.:../..", wup->project->project_dir()); #ifdef __APPLE__ strcat(newlibs, ":/usr/local/cuda/lib/"); #endif diff --git a/client/cs_account.cpp b/client/cs_account.cpp index 5706fb47f3..04d1981448 100644 --- a/client/cs_account.cpp +++ b/client/cs_account.cpp @@ -479,7 +479,7 @@ int CLIENT_STATE::add_project( const char* master_url, const char* _auth, const char* project_name, bool attached_via_acct_mgr ) { - char path[MAXPATHLEN], canonical_master_url[256], auth[256], dir[256]; + char path[MAXPATHLEN], canonical_master_url[256], auth[256]; PROJECT* project; FILE* f; int retval; @@ -532,8 +532,7 @@ int CLIENT_STATE::add_project( // (unless PROJECT/app_info.xml is found, so that // people using anonymous platform don't have to get apps again) // - get_project_dir(project, dir, sizeof(dir)); - sprintf(path, "%s/%s", dir, APP_INFO_FILE_NAME); + sprintf(path, "%s/%s", project->project_dir(), APP_INFO_FILE_NAME); if (boinc_file_exists(path)) { project->anonymous_platform = true; f = fopen(path, "r"); diff --git a/client/cs_prefs.cpp b/client/cs_prefs.cpp index 34510e6b51..726d655021 100644 --- a/client/cs_prefs.cpp +++ b/client/cs_prefs.cpp @@ -79,19 +79,18 @@ double CLIENT_STATE::allowed_disk_usage(double boinc_total) { // GLOBAL_STATE::total_disk_usage // int CLIENT_STATE::get_disk_usages() { - char buf[256]; unsigned int i; double size; PROJECT* p; int retval; + char buf[MAXPATHLEN]; client_disk_usage = 0; total_disk_usage = 0; for (i=0; idisk_usage = 0; - get_project_dir(p, buf, sizeof(buf)); - retval = dir_size(buf, size); + retval = dir_size(p->project_dir(), size); if (!retval) p->disk_usage = size; } diff --git a/client/cs_statefile.cpp b/client/cs_statefile.cpp index b52d64a5b1..7a7c4e732e 100644 --- a/client/cs_statefile.cpp +++ b/client/cs_statefile.cpp @@ -806,14 +806,13 @@ int CLIENT_STATE::write_state_file_if_needed() { // void CLIENT_STATE::check_anonymous() { unsigned int i; - char dir[256], path[MAXPATHLEN]; + char path[MAXPATHLEN]; FILE* f; int retval; for (i=0; iproject_dir(), APP_INFO_FILE_NAME); f = fopen(path, "r"); if (!f) continue; msg_printf(p, MSG_INFO, diff --git a/client/cs_trickle.cpp b/client/cs_trickle.cpp index ed516e5be7..f97820cd65 100644 --- a/client/cs_trickle.cpp +++ b/client/cs_trickle.cpp @@ -46,14 +46,13 @@ using std::string; // Convert them to XML (for sched request message) // int CLIENT_STATE::read_trickle_files(PROJECT* project, FILE* f) { - char project_dir[256], *p, *q, result_name[256], fname[256]; + char *p, *q, result_name[256], fname[256]; char* file_contents, path[MAXPATHLEN], newpath[MAXPATHLEN]; string fn; time_t t; int retval; - get_project_dir(project, project_dir, sizeof(project_dir)); - DirScanner ds(project_dir); + DirScanner ds(project->project_dir()); // trickle-up filenames are of the form trickle_up_RESULTNAME_TIME[.sent] // @@ -68,7 +67,7 @@ int CLIENT_STATE::read_trickle_files(PROJECT* project, FILE* f) { *p = '_'; t = atoi(p+1); - sprintf(path, "%s/%s", project_dir, fname); + sprintf(path, "%s/%s", project->project_dir(), fname); retval = read_file_malloc(path, file_contents); if (retval) continue; fprintf(f, @@ -87,7 +86,7 @@ int CLIENT_STATE::read_trickle_files(PROJECT* project, FILE* f) { // append .sent to filename, so we'll know which ones to delete later // if (!ends_with(fname, ".sent")) { - sprintf(newpath, "%s/%s.sent", project_dir, fname); + sprintf(newpath, "%s/%s.sent", project->project_dir(), fname); boinc_rename(path, newpath); } } @@ -99,17 +98,16 @@ int CLIENT_STATE::read_trickle_files(PROJECT* project, FILE* f) { // (others arrived from application while RPC was happening) // int CLIENT_STATE::remove_trickle_files(PROJECT* project) { - char project_dir[256], path[MAXPATHLEN], fname[256]; + char path[MAXPATHLEN], fname[256]; string fn; - get_project_dir(project, project_dir, sizeof(project_dir)); - DirScanner ds(project_dir); + DirScanner ds(project->project_dir()); while (ds.scan(fn)) { strcpy(fname, fn.c_str()); if (!starts_with(fname, "trickle_up")) continue; if (!ends_with(fname, ".sent")) continue; - sprintf(path, "%s/%s", project_dir, fname); + sprintf(path, "%s/%s", project->project_dir(), fname); delete_project_owned_file(path, true); } return 0; diff --git a/client/file_names.cpp b/client/file_names.cpp index 6af9aa72dc..36d5aa0c12 100644 --- a/client/file_names.cpp +++ b/client/file_names.cpp @@ -65,12 +65,6 @@ int make_soft_link(PROJECT* project, char* link_path, char* rel_file_path) { return 0; } -void get_project_dir(PROJECT* p, char* path, int len) { - char buf[1024]; - escape_project_url(p->master_url, buf); - snprintf(path, len, "%s/%s", PROJECTS_DIR, buf); -} - // Gets the pathname of a file // void get_pathname(FILE_INFO* fip, char* path, int len) { @@ -85,10 +79,10 @@ void get_pathname(FILE_INFO* fip, char* path, int len) { if (fip->is_auto_update_file) { boinc_version_dir(*p, gstate.auto_update.version, buf); } else { - get_project_dir(p, buf, sizeof(buf)); + strcpy(buf, p->project_dir()); } #else - get_project_dir(p, buf, sizeof(buf)); + strcpy(buf, p->project_dir()); #endif snprintf(path, len, "%s/%s", buf, fip->name); } else { @@ -133,7 +127,6 @@ void get_slot_dir(int slot, char* path, int len) { // Create the directory for the project p // int make_project_dir(PROJECT& p) { - char buf[1024]; int retval; boinc_mkdir(PROJECTS_DIR); @@ -151,36 +144,33 @@ int make_project_dir(PROJECT& p) { set_to_project_group(PROJECTS_DIR); } #endif - get_project_dir(&p, buf, sizeof(buf)); - retval = boinc_mkdir(buf); + retval = boinc_mkdir(p.project_dir()); #ifndef _WIN32 if (g_use_sandbox) { old_mask = umask(2); // Contents of projects directory must be world-readable so BOINC Client can read // files written by projects which have user boinc_project and group boinc_project - chmod(buf, + chmod(p.project_dir(), S_IRUSR|S_IWUSR|S_IXUSR |S_IRGRP|S_IWGRP|S_IXGRP |S_IROTH|S_IXOTH ); umask(old_mask); - set_to_project_group(buf); + set_to_project_group(p.project_dir()); } #endif return retval; } int remove_project_dir(PROJECT& p) { - char buf[1024]; int retval; - get_project_dir(&p, buf, sizeof(buf)); - retval = client_clean_out_dir(buf, "remove project dir"); + retval = client_clean_out_dir(p.project_dir(), "remove project dir"); if (retval) { msg_printf(&p, MSG_INTERNAL_ERROR, "Can't delete file %s", boinc_failed_file); return retval; } - return remove_project_owned_dir(buf); + return remove_project_owned_dir(p.project_dir()); } // Create the slot directory for the specified slot # @@ -341,9 +331,9 @@ bool is_image_file(const char* filename) { } void boinc_version_dir(PROJECT& p, VERSION_INFO& vi, char* buf) { - char projdir[1024]; - get_project_dir(&p, projdir, sizeof(projdir)); - sprintf(buf, "%s/boinc_version_%d_%d_%d", projdir, vi.major, vi.minor, vi.release); + sprintf(buf, "%s/boinc_version_%d_%d_%d", + p.project_dir(), vi.major, vi.minor, vi.release + ); } bool is_version_dir(char* buf, VERSION_INFO& vi) { diff --git a/client/file_names.h b/client/file_names.h index 378c4a7d90..27fd475c22 100644 --- a/client/file_names.h +++ b/client/file_names.h @@ -27,7 +27,6 @@ extern int make_soft_link(PROJECT* project, char* link_path, char* rel_file_path // get the pathname (relative to client home dir) of a project file // extern void get_pathname(FILE_INFO* fip, char* path, int len); -extern void get_project_dir(PROJECT*, char*, int); // get the pathname (relative to client home dir) of the // directory used for a particular application "slot" diff --git a/client/project.cpp b/client/project.cpp index 7f5ea97c0e..c807c4bf20 100644 --- a/client/project.cpp +++ b/client/project.cpp @@ -18,6 +18,7 @@ #include #include "str_replace.h" +#include "url.h" #include "client_msgs.h" #include "client_state.h" @@ -468,9 +469,7 @@ int PROJECT::write_state(MIOFILE& out, bool gui_rpc) { if (strlen(host_venue)) { out.printf(" %s\n", host_venue); } - char project_dir[MAXPATHLEN]; - get_project_dir(this, project_dir, sizeof(project_dir)); - out.printf(" %s\n", project_dir); + out.printf(" %s\n", project_dir_absolute()); } else { for (i=0; iname); + sprintf(link_path, "%s/%s", project_dir(), fref.open_name); + sprintf(file_path, "%s/%s", project_dir(), fip->name); make_soft_link(this, link_path, file_path); } return 0; @@ -858,3 +855,19 @@ void PROJECT::trim_statistics() { } } } + +const char* PROJECT::project_dir() { + if (_project_dir[0] == 0) { + char buf[1024]; + escape_project_url(master_url, buf); + sprintf(_project_dir, "%s/%s", PROJECTS_DIR, buf); + } + return _project_dir; +} + +const char* PROJECT::project_dir_absolute() { + if (_project_dir_absolute[0] == 0) { + relative_to_absolute(project_dir(), _project_dir_absolute); + } + return _project_dir_absolute; +} diff --git a/client/project.h b/client/project.h index 2c8f88b3df..14907206e4 100644 --- a/client/project.h +++ b/client/project.h @@ -22,6 +22,9 @@ #include "client_types.h" struct PROJECT : PROJ_AM { + char _project_dir[MAXPATHLEN]; + char _project_dir_absolute[MAXPATHLEN]; + // the following items come from the account file // They are a function only of the user and the project // @@ -300,6 +303,8 @@ struct PROJECT : PROJ_AM { int parse_account_file(); int parse_state(XML_PARSER&); int write_state(MIOFILE&, bool gui_rpc=false); + const char* project_dir(); + const char* project_dir_absolute(); // statistic of the last x days std::vector statistics;