Use _DC_copyFile

git-svn-id: svn+ssh://cvs.lpds.sztaki.hu/var/lib/svn/szdg/dcapi/trunk@440 a7169a2c-3604-0410-bc95-c702d8d87f7a
This commit is contained in:
gombasg 2006-04-10 12:44:54 +00:00 committed by Adam Visegradi
parent 188525a448
commit 00d8134349
1 changed files with 3 additions and 71 deletions

View File

@ -2,12 +2,13 @@
#include <config.h>
#endif
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <fcntl.h>
#include <glib.h>
#include <sched_util.h>
@ -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);