diff --git a/dcapi/boinc/wu.C b/dcapi/boinc/wu.C index 545a62abf3..a42229218b 100644 --- a/dcapi/boinc/wu.C +++ b/dcapi/boinc/wu.C @@ -2,12 +2,13 @@ #include #endif +#include +#include #include #include #include #include #include -#include #include #include @@ -30,9 +31,6 @@ typedef enum WU_SUBRESULTS, } wu_tag; -/* Buffer size used when copying a file */ -#define COPY_BUFSIZE 65536 - /******************************************************************** * Data type definitions @@ -208,72 +206,6 @@ static char *get_input_download_path(DC_Workunit *wu, const char *label) return g_strdup(path); } -static int copy_file(const char *src, const char *dst) -{ - int sfd, dfd; - ssize_t ret; - char *buf; - - buf = (char *)g_malloc(COPY_BUFSIZE); - sfd = open(src, O_RDONLY); - if (sfd == -1) - { - DC_log(LOG_ERR, "Failed to open %s for copying: %s", src, - strerror(errno)); - g_free(buf); - return -1; - } - dfd = open(dst, O_WRONLY | O_CREAT | O_TRUNC); - if (dfd == -1) - { - DC_log(LOG_ERR, "Failed to create %s: %s", dst, strerror(errno)); - g_free(buf); - close(sfd); - return -1; - } - - while ((ret = read(sfd, buf, COPY_BUFSIZE)) > 0) - { - char *ptr = buf; - while (ret) - { - ssize_t ret2 = write(dfd, ptr, ret); - if (ret2 < 0) - { - DC_log(LOG_ERR, "Error writing to %s: %s", dst, - strerror(errno)); - close(sfd); - close(dfd); - unlink(dst); - g_free(buf); - return -1; - } - ret -= ret2; - ptr += ret2; - } - } - - if (ret < 0) - { - DC_log(LOG_ERR, "Error reading from %s: %s", src, strerror(errno)); - close(sfd); - close(dfd); - g_free(buf); - unlink(dst); - return -1; - } - - g_free(buf); - close(sfd); - if (close(dfd)) - { - DC_log(LOG_ERR, "Error writing to %s: %s", dst, strerror(errno)); - unlink(dst); - return -1; - } - return 0; -} - static int wu_uuid_equal(const void *a, const void *b) { return uuid_compare((const unsigned char *)a, @@ -554,7 +486,7 @@ int DC_addWUInput(DC_Workunit *wu, const char *logicalFileName, const char *URL, switch (fileMode) { case DC_FILE_REGULAR: - ret = copy_file(URL, file->path); + ret = _DC_copyFile(URL, file->path); if (ret) { _DC_destroyPhysicalFile(file);