- client: more fixes to GUI RPC addition.

Also, replace get_project_dir() with a memoized member function of PROJECT
This commit is contained in:
David Anderson 2013-04-18 13:57:33 -07:00
parent 0880c7107a
commit 64d7fa3474
11 changed files with 57 additions and 62 deletions

View File

@ -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);

View File

@ -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; i<gstate.projects.size(); i++) {
PROJECT* p = gstate.projects[i];
get_project_dir(p, dir, sizeof(dir));
sprintf(path, "%s/%s", dir, APP_CONFIG_FILE_NAME);
sprintf(path, "%s/%s", p->project_dir(), APP_CONFIG_FILE_NAME);
f = boinc_fopen(path, "r");
if (!f) continue;
msg_printf(p, MSG_INFO,

View File

@ -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

View File

@ -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");

View File

@ -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; i<projects.size(); i++) {
p = projects[i];
p->disk_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;
}

View File

@ -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; i<projects.size(); i++) {
PROJECT* p = projects[i];
get_project_dir(p, dir, sizeof(dir));
sprintf(path, "%s/%s", dir, APP_INFO_FILE_NAME);
sprintf(path, "%s/%s", p->project_dir(), APP_INFO_FILE_NAME);
f = fopen(path, "r");
if (!f) continue;
msg_printf(p, MSG_INFO,

View File

@ -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;

View File

@ -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) {

View File

@ -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"

View File

@ -18,6 +18,7 @@
#include <string.h>
#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(" <venue>%s</venue>\n", host_venue);
}
char project_dir[MAXPATHLEN];
get_project_dir(this, project_dir, sizeof(project_dir));
out.printf(" <project_dir>%s</project_dir>\n", project_dir);
out.printf(" <project_dir>%s</project_dir>\n", project_dir_absolute());
} else {
for (i=0; i<scheduler_urls.size(); i++) {
out.printf(
@ -639,12 +638,11 @@ const char* PROJECT::get_scheduler_url(int index, double r) {
//
void PROJECT::delete_project_file_symlinks() {
unsigned int i;
char project_dir[256], path[MAXPATHLEN];
char path[MAXPATHLEN];
get_project_dir(this, project_dir, sizeof(project_dir));
for (i=0; i<project_files.size(); i++) {
FILE_REF& fref = project_files[i];
sprintf(path, "%s/%s", project_dir, fref.open_name);
sprintf(path, "%s/%s", project_dir(), fref.open_name);
delete_project_owned_file(path, false);
}
}
@ -698,15 +696,14 @@ void PROJECT::write_project_files(MIOFILE& f) {
// has several logical names, so try them all
//
int PROJECT::write_symlink_for_project_file(FILE_INFO* fip) {
char project_dir[256], link_path[MAXPATHLEN], file_path[MAXPATHLEN];
char link_path[MAXPATHLEN], file_path[MAXPATHLEN];
unsigned int i;
get_project_dir(this, project_dir, sizeof(project_dir));
for (i=0; i<project_files.size(); i++) {
FILE_REF& fref = project_files[i];
if (fref.file_info != fip) continue;
sprintf(link_path, "%s/%s", project_dir, fref.open_name);
sprintf(file_path, "%s/%s", project_dir, fip->name);
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;
}

View File

@ -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<DAILY_STATS> statistics;