Skip to content

Commit 6f31742

Browse files
authored
Merge pull request #5482 from BOINC/dpa_acct_file
client: handle changes to project master URLs
2 parents 74329dc + 1c3d99e commit 6f31742

File tree

3 files changed

+102
-9
lines changed

3 files changed

+102
-9
lines changed

Diff for: client/cs_account.cpp

+39-4
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ int CLIENT_STATE::parse_account_files() {
323323
PROJECT* project;
324324
FILE* f;
325325
int retval;
326+
char path[MAXPATHLEN];
326327

327328
DirScanner dir(".");
328329
while (dir.scan(name)) {
@@ -345,16 +346,50 @@ int CLIENT_STATE::parse_account_files() {
345346
"Couldn't parse account file %s", name.c_str()
346347
);
347348
delete project;
348-
} else {
349-
if (lookup_project(project->master_url)) {
349+
continue;
350+
}
351+
352+
// see if the account file name doesn't match the master URL.
353+
// This can happen if a project changes its URL
354+
//
355+
// If this happens, anything in client_state.xml for the old project
356+
// will be ignored.
357+
//
358+
get_account_filename(project->master_url, path, sizeof(path));
359+
if (strcmp(path, name.c_str())) {
360+
// if not, see if account file with proper name exists
361+
//
362+
if (boinc_file_exists(path)) {
363+
// yes - delete this file
364+
//
350365
msg_printf(project, MSG_INFO,
351-
"Duplicate account file %s - ignoring", name.c_str()
366+
"Misnamed account file %s - deleting", name.c_str()
352367
);
368+
boinc_delete_file(name.c_str());
353369
delete project;
370+
continue;
354371
} else {
355-
projects.push_back(project);
372+
// no - rename this file
373+
//
374+
msg_printf(project, MSG_INFO,
375+
"Misnamed account file %s - renaming to %s",
376+
name.c_str(), path
377+
);
378+
boinc_rename(name.c_str(), path);
356379
}
357380
}
381+
382+
// shouldn't happen given the above logic, but just in case
383+
//
384+
if (lookup_project(project->master_url)) {
385+
msg_printf(project, MSG_INFO,
386+
"Duplicate account file %s - ignoring", name.c_str()
387+
);
388+
delete project;
389+
continue;
390+
}
391+
392+
projects.push_back(project);
358393
}
359394
return 0;
360395
}

Diff for: client/cs_files.cpp

+26-2
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,39 @@ bool CLIENT_STATE::start_new_file_xfer(PERS_FILE_XFER& pfx) {
8787
return true;
8888
}
8989

90-
// Make a directory for each of the projects in the client state
90+
// Make a directory for each of the projects in the client state,
91+
// and delete other stuff in projects/
9192
//
9293
int CLIENT_STATE::make_project_dirs() {
9394
unsigned int i;
9495
int retval;
96+
vector<string> pds;
9597
for (i=0; i<projects.size(); i++) {
96-
retval = make_project_dir(*projects[i]);
98+
PROJECT *p = projects[i];
99+
retval = make_project_dir(*p);
97100
if (retval) return retval;
101+
pds.push_back(p->project_dir());
98102
}
103+
104+
string name;
105+
char path[MAXPATHLEN];
106+
DirScanner dir("projects");
107+
while (dir.scan(name)) {
108+
snprintf(path, sizeof(path), "projects/%s", name.c_str());
109+
if (std::find(pds.begin(), pds.end(), path) != pds.end()) {
110+
continue;
111+
}
112+
msg_printf(0, MSG_INFO,
113+
"%s is not a project dir - removing", path
114+
);
115+
if (is_dir(path)) {
116+
clean_out_dir(path);
117+
boinc_rmdir(path);
118+
} else {
119+
boinc_delete_file(path);
120+
}
121+
}
122+
99123
return 0;
100124
}
101125

Diff for: client/cs_scheduler.cpp

+37-3
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,9 @@ int CLIENT_STATE::handle_scheduler_reply(
567567
// (which comes from the project's config.xml).
568568
// - if http -> https transition, use the https: one from now on
569569
// - if https -> http transition, keep using the https: one
570-
// - otherwise notify the user.
570+
// - otherwise switch to the new master URL:
571+
// rename and rewrite account file
572+
// rename project dir
571573
//
572574
if (strlen(sr.master_url)) {
573575
canonicalize_master_url(sr.master_url, sizeof(sr.master_url));
@@ -587,9 +589,41 @@ int CLIENT_STATE::handle_scheduler_reply(
587589
// keep using https://
588590
} else {
589591
msg_printf(project, MSG_USER_ALERT,
590-
_("This project seems to have changed its URL. When convenient, remove the project, then add %s"),
591-
sr.master_url
592+
_("Master URL changed from %s to %s"),
593+
current_url.c_str(), reply_url.c_str()
592594
);
595+
char path[MAXPATHLEN], path2[MAXPATHLEN], old_project_dir[MAXPATHLEN];
596+
597+
// rename statistics file
598+
//
599+
get_statistics_filename(
600+
(char*)current_url.c_str(), path, sizeof(path)
601+
);
602+
get_statistics_filename(
603+
(char*)reply_url.c_str(), path2, sizeof(path2)
604+
);
605+
boinc_rename(path, path2);
606+
607+
strcpy(old_project_dir, project->project_dir());
608+
609+
// delete account file and write new one
610+
//
611+
get_account_filename(project->master_url, path, sizeof(path));
612+
boinc_delete_file(path);
613+
strcpy(project->master_url, reply_url.c_str());
614+
project->write_account_file();
615+
616+
// rename project dir
617+
//
618+
strcpy(project->_project_dir, "");
619+
strcpy(path2, project->project_dir());
620+
boinc_rename(old_project_dir, path2);
621+
622+
// reset the project (clear jobs etc.).
623+
// If any jobs are running, their soft links
624+
// point to the old project dir
625+
//
626+
reset_project(project, false);
593627
}
594628
}
595629
}

0 commit comments

Comments
 (0)