summaryrefslogtreecommitdiff
path: root/mysys/my_copy.c
diff options
context:
space:
mode:
authorMichael Widenius <monty@askmonty.org>2010-08-27 17:12:44 +0300
committerMichael Widenius <monty@askmonty.org>2010-08-27 17:12:44 +0300
commitad6d95d3cb420557cfc7efa658181a8d20b4c154 (patch)
tree984bb45ca187a6cc38c7132a9600d91515df564e /mysys/my_copy.c
parent9bc9855c16f815e71223398ef17cd6052becc44e (diff)
parent7909541953de43c7b7d16513c8d612cfe405af67 (diff)
downloadmariadb-git-ad6d95d3cb420557cfc7efa658181a8d20b4c154.tar.gz
Merge with MySQL 5.1.50
- Changed to still use bcmp() in certain cases becasue - Faster for short unaligneed strings than memcmp() - Bettern when using valgrind - Changed to use my_sprintf() instead of sprintf() to get higher portability for old systems - Changed code to use MariaDB version of select->skip_record() - Removed -%::SCCS/s.% from Makefile.am:s to remove automake warnings
Diffstat (limited to 'mysys/my_copy.c')
-rw-r--r--mysys/my_copy.c33
1 files changed, 25 insertions, 8 deletions
diff --git a/mysys/my_copy.c b/mysys/my_copy.c
index adc891358d4..8ea9620b20b 100644
--- a/mysys/my_copy.c
+++ b/mysys/my_copy.c
@@ -17,6 +17,7 @@
#include "mysys_err.h"
#include <my_dir.h> /* for stat */
#include <m_string.h>
+#include "mysys_err.h"
#if defined(HAVE_UTIME_H)
#include <utime.h>
#elif defined(HAVE_SYS_UTIME_H)
@@ -57,7 +58,7 @@ int my_copy(const char *from, const char *to, myf MyFlags)
File from_file,to_file;
uchar buff[IO_SIZE];
MY_STAT stat_buff,new_stat_buff;
- int res;
+ my_bool file_created= 0;
DBUG_ENTER("my_copy");
DBUG_PRINT("my",("from %s to %s MyFlags %d", from, to, MyFlags));
@@ -82,6 +83,7 @@ int my_copy(const char *from, const char *to, myf MyFlags)
MyFlags)) < 0)
goto err;
+ file_created= 1;
while ((Count=my_read(from_file, buff, sizeof(buff), MyFlags)) != 0)
{
if (Count == (uint) -1 ||
@@ -99,15 +101,30 @@ int my_copy(const char *from, const char *to, myf MyFlags)
if (my_close(from_file,MyFlags) | my_close(to_file,MyFlags))
DBUG_RETURN(-1); /* Error on close */
+ from_file=to_file= -1; /* Files are closed */
+
/* Copy modes if possible */
if (MyFlags & MY_HOLD_ORIGINAL_MODES && !new_file_stat)
DBUG_RETURN(0); /* File copyed but not stat */
- res= chmod(to, stat_buff.st_mode & 07777); /* Copy modes */
+ /* Copy modes */
+ if (chmod(to, stat_buff.st_mode & 07777))
+ {
+ my_errno= errno;
+ if (MyFlags & MY_WME)
+ my_error(EE_CHANGE_PERMISSIONS, MYF(ME_BELL+ME_WAITTANG), from, errno);
+ if (MyFlags & MY_FAE)
+ goto err;
+ }
#if !defined(__WIN__) && !defined(__NETWARE__)
+ /* Copy ownership */
if (chown(to, stat_buff.st_uid,stat_buff.st_gid))
{
- my_error(EE_CANT_COPY_OWNERSHIP, MYF(ME_JUST_WARNING), to);
+ my_errno= errno;
+ if (MyFlags & MY_WME)
+ my_error(EE_CANT_COPY_OWNERSHIP, MYF(ME_JUST_WARNING), to, errno);
+ if (MyFlags & MY_FAE)
+ goto err;
}
#endif
#if !defined(VMS) && !defined(__ZTC__)
@@ -124,11 +141,11 @@ int my_copy(const char *from, const char *to, myf MyFlags)
err:
if (from_file >= 0) VOID(my_close(from_file,MyFlags));
- if (to_file >= 0)
- {
- VOID(my_close(to_file, MyFlags));
- /* attempt to delete the to-file we've partially written */
+ if (to_file >= 0) VOID(my_close(to_file, MyFlags));
+
+ /* attempt to delete the to-file we've partially written */
+ if (file_created)
VOID(my_delete(to, MyFlags));
- }
+
DBUG_RETURN(-1);
} /* my_copy */