- API: change boinc_resolve_filename() so that it detects symbolic links

and treats them as a special case.
    Also, if the virtual file doesn't exist (as in the standalone case)
    just return zero; otherwise if the app is running standalone
    and checks the return value, it will error out.

    NOTE: apps that check the return value of boinc_resolve_filename()
    won't work on 6.12+ under Unix;
    recompiling with this change will fix the problem.

svn path=/trunk/boinc/; revision=15012
This commit is contained in:
David Anderson 2008-04-03 21:59:05 +00:00
parent 91ce899042
commit e584774f08
4 changed files with 44 additions and 6 deletions

View File

@ -3055,3 +3055,18 @@ Rom April 3 2008
CACreateBOINCAccounts.cpp
CACreateBOINCGroups.cpp
CAMigrateBOINCData.cpp
David April 3 2008
- API: change boinc_resolve_filename() so that it detects symbolic links
and treats them as a special case.
Also, if the virtual file doesn't exist (as in the standalone case)
just return zero; otherwise if the app is running standalone
and checks the return value, it will error out.
NOTE: apps that check the return value of boinc_resolve_filename()
won't work on 6.12+ under Unix;
recompiling with this change will fix the problem.
lib/
app_ipc.C
filesys.C,h

View File

@ -302,24 +302,38 @@ void APP_CLIENT_SHM::reset_msgs() {
memset(shm, 0, sizeof(SHARED_MEM));
}
// resolve "symbolic link"
// Resolve virtual name (in slot dir) to physical path (in project dir).
// Cases:
// - Windows and pre-6.12 Unix:
// virtual name refers to a "soft link" (XML file acting as symbolic link)
// - 6.12+ Unix:
// virtual name is a symbolic link
// - Standalone: physical path is same as virtual name
//
int boinc_resolve_filename(const char *virtual_name, char *physical_name, int len) {
int boinc_resolve_filename(
const char *virtual_name, char *physical_name, int len
) {
FILE *fp;
char buf[512], *p;
if (!virtual_name) return ERR_NULL;
strlcpy(physical_name, virtual_name, len);
#ifndef _WIN32
if (is_symlink(virtual_name)) {
return 0;
}
#endif
// Open the link file and read the first line
//
fp = boinc_fopen(virtual_name, "r");
if (!fp) return ERR_FOPEN;
if (!fp) return 0;
// must initialize buf since fgets() on an empty file won't do anything
//
buf[0] = 0;
p =fgets(buf, 512, fp);
p =fgets(buf, sizeof(buf), fp);
fclose(fp);
// If it's the <soft_link> XML tag, return its value,

View File

@ -88,6 +88,14 @@ int is_dir(const char* path) {
return (!retval && (sbuf.st_mode & S_IFDIR));
}
#ifndef _WIN32
int is_symlink(const char* path) {
struct stat sbuf;
int retval = stat(path, &sbuf);
return (!retval && (sbuf.st_mode & S_IFLNK));
}
#endif
// Open a directory
//
DIRREF dir_open(const char* p) {
@ -337,7 +345,7 @@ int clean_out_dir(const char* dirpath) {
// return total size of files in directory and optionally its subdirectories
// Win: use special version because stat() is slow, can be avoided
// Unix: skip symbolic links
// Unix: follow symbolic links
//
int dir_size(const char* dirpath, double& size, bool recurse) {
#ifdef WIN32
@ -386,7 +394,7 @@ int dir_size(const char* dirpath, double& size, bool recurse) {
if (retval) continue;
size += x;
}
} else if (is_file(subdir)) {
} else {
retval = file_size(subdir, x);
if (retval) continue;
size += x;

View File

@ -57,6 +57,7 @@ extern "C" {
extern char boinc_failed_file[256];
extern int is_file(const char* path);
extern int is_dir(const char* path);
extern int is_symlink(const char* path);
extern int boinc_truncate(const char*, double);
extern int boinc_file_exists(const char* path);
extern int boinc_file_or_symlink_exists(const char* path);