Skip to content

Commit

Permalink
Move the error logging to _DC_copyFile()
Browse files Browse the repository at this point in the history
git-svn-id: svn+ssh://cvs.lpds.sztaki.hu/var/lib/svn/szdg/dcapi/trunk@1939 a7169a2c-3604-0410-bc95-c702d8d87f7a
  • Loading branch information
gombasg authored and Adam Visegradi committed Dec 2, 2013
1 parent afcc963 commit 7072a98
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
4 changes: 2 additions & 2 deletions dcapi/boinc/result.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ DC_Result *_DC_createResult(const char *wu_name, int db_id,
ret = _DC_copyFile(upload_path, workdir_path);
if (ret)
DC_log(LOG_ERR, "Failed to copy the output "
"file %s to %s: %s", upload_path,
workdir_path, strerror(errno));
"file %s to %s", upload_path,
workdir_path);
}
g_free(workdir_path);
g_free(upload_path);
Expand Down
20 changes: 9 additions & 11 deletions dcapi/common/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,25 +47,28 @@ int _DC_copyFile(const char *src, const char *dst)

buf = (char *)malloc(COPY_BUFSIZE);
if (!buf)
{
DC_log(LOG_ERR, "_DC_copyFile: Out of memory");
return DC_ERR_SYSTEM;
}

sfd = open(src, O_RDONLY);
if (sfd == -1)
{
ret = errno;
DC_log(LOG_ERR, "_DC_copyFile: failed to open source file %s: %s",
src, strerror(errno));
free(buf);
errno = ret;
return DC_ERR_SYSTEM;
}

fstat(sfd, &s);
dfd = open(dst, O_WRONLY | O_CREAT | O_TRUNC, s.st_mode);
if (dfd == -1)
{
ret = errno;
DC_log(LOG_ERR, "_DC_copyFile: failed to create destination file %s: %s",
dst, strerror(errno));
free(buf);
close(sfd);
errno = ret;
return DC_ERR_SYSTEM;
}

Expand All @@ -76,10 +79,7 @@ int _DC_copyFile(const char *src, const char *dst)
{
ssize_t ret2 = write(dfd, ptr, ret);
if (ret2 < 0)
{
ret = errno;
goto error;
}
ret -= ret2;
ptr += ret2;
}
Expand All @@ -92,20 +92,18 @@ int _DC_copyFile(const char *src, const char *dst)
close(sfd);
if (close(dfd))
{
ret = errno;
DC_log(LOG_ERR, "_DC_copyFile: I/O error: %s", strerror(errno));
unlink(dst);
errno = ret;
return DC_ERR_SYSTEM;
}
return 0;

error:
ret = errno;
DC_log(LOG_ERR, "_DC_copyFile: I/O error: %s", strerror(errno));
free(buf);
close(sfd);
close(dfd);
unlink(dst);
errno = ret;
return DC_ERR_SYSTEM;
}
#endif /* _WIN32 */
Expand Down

0 comments on commit 7072a98

Please sign in to comment.