lib, Unix: remove chown/chmod stuff from boinc_copy().

boinc_copy() is used in both client and server.
The chown/chmod was added Jan 6 2009,
apparently to deal with a client problem.
More recently, error checking was added to the chown/chmod calls.
On the server (e.g. sample assimilator) these fail,
and boinc_copy() returns error (even though the file was actually copied).

1) let's not overload functions.  Functions in general should do 1 thing.
To this end, I moved the chown/chmod to a new function, boinc_copy_attributes().

2) It's not clear to me that we need the chown/chmod stuff,
either on client or server.
On the Unix client, we already have FILE_INFO::set_permissions(),
which sets the rwx bits of files copied into slot directories, as appropriate.
The chown() will be a no-op, since the client creates
both the original file (in project dir) and the copy.

So I'm not going to call boinc_copy_attributes() in the client.
Let's see if any problems arise in Unix with apps that
used <copy_file> for executables.
This commit is contained in:
David Anderson 2016-01-30 13:48:06 -08:00
parent 12692d3a3c
commit 3f2cd00b30
2 changed files with 19 additions and 8 deletions

View File

@ -580,7 +580,6 @@ int boinc_copy(const char* orig, const char* newf) {
FILE *src, *dst;
int m, n;
int retval = 0;
struct stat sbuf;
unsigned char buf[65536];
src = boinc_fopen(orig, "r");
if (!src) return ERR_FOPEN;
@ -600,19 +599,30 @@ int boinc_copy(const char* orig, const char* newf) {
}
fclose(src);
fclose(dst);
// Copy file's ownership, permissions to the extent we are allowed
if (lstat(orig, &sbuf)) { // Get source file's info
return retval;
#endif
}
#ifndef _WIN32
// Copy file's ownership and permissions to the extent we are allowed
//
int boinc_copy_attributes(const char* orig, const char* newf) {
struct stat sbuf;
// Get source file's info
//
if (lstat(orig, &sbuf)) {
return ERR_STAT;
}
if (chown(newf, sbuf.st_uid, sbuf.st_gid)) {
return ERR_CHOWN;
}
if (chmod(newf, sbuf.st_mode)) {
return ERR_CHMOD;
}
return retval;
#endif
if (chown(newf, sbuf.st_uid, sbuf.st_gid)) {
return ERR_CHOWN;
}
return 0;
}
#endif
static int boinc_rename_aux(const char* old, const char* newf) {
#ifdef _WIN32

View File

@ -55,6 +55,7 @@ extern "C" {
#ifdef _WIN32
extern int boinc_allocate_file(const char*, double size);
#else
extern int boinc_copy_attributes(const char* orig, const char* newf);
extern int boinc_chown(const char*, gid_t);
#endif
extern int boinc_rmdir(const char*);