summaryrefslogtreecommitdiff
path: root/mysys/my_copy.c
diff options
context:
space:
mode:
Diffstat (limited to 'mysys/my_copy.c')
-rw-r--r--mysys/my_copy.c29
1 files changed, 18 insertions, 11 deletions
diff --git a/mysys/my_copy.c b/mysys/my_copy.c
index 35324dd4cef..17bb796fd9b 100644
--- a/mysys/my_copy.c
+++ b/mysys/my_copy.c
@@ -14,6 +14,7 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#include "mysys_priv.h"
+#include "mysys_err.h"
#include <my_dir.h> /* for stat */
#include <m_string.h>
#include "mysys_err.h"
@@ -57,6 +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;
+ my_bool file_created= 0;
DBUG_ENTER("my_copy");
DBUG_PRINT("my",("from %s to %s MyFlags %d", from, to, MyFlags));
@@ -81,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 ||
@@ -98,6 +101,8 @@ 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)
@@ -106,18 +111,20 @@ int my_copy(const char *from, const char *to, myf MyFlags)
if (chmod(to, stat_buff.st_mode & 07777))
{
my_errno= errno;
- if (MyFlags & (MY_FAE+MY_WME))
- my_error(EE_CHANGE_PERMISSIONS, MYF(ME_BELL+ME_WAITTANG), from, errno);
- goto err;
+ if (MyFlags & MY_WME)
+ my_error(EE_CHANGE_PERMISSIONS, MYF(ME_BELL+ME_WAITTANG), to, errno);
+ if (MyFlags & MY_FAE)
+ goto err;
}
#if !defined(__WIN__)
/* Copy ownership */
if (chown(to, stat_buff.st_uid, stat_buff.st_gid))
{
my_errno= errno;
- if (MyFlags & (MY_FAE+MY_WME))
- my_error(EE_CHANGE_OWNERSHIP, MYF(ME_BELL+ME_WAITTANG), from, errno);
- goto err;
+ if (MyFlags & MY_WME)
+ my_error(EE_CANT_COPY_OWNERSHIP, MYF(ME_JUST_WARNING), to, errno);
+ if (MyFlags & MY_FAE)
+ goto err;
}
#endif
@@ -134,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 */