From 00d813434937d4c9dc6670e02aa0a96ec1de2e45 Mon Sep 17 00:00:00 2001 From: gombasg Date: Mon, 10 Apr 2006 12:44:54 +0000 Subject: [PATCH] Use _DC_copyFile git-svn-id: svn+ssh://cvs.lpds.sztaki.hu/var/lib/svn/szdg/dcapi/trunk@440 a7169a2c-3604-0410-bc95-c702d8d87f7a --- dcapi/boinc/wu.C | 74 ++---------------------------------------------- 1 file changed, 3 insertions(+), 71 deletions(-) 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);