#include "mysys_priv.h"#include <my_dir.h>#include <m_string.h>#include <time.h>Include dependency graph for my_copy.c:

Go to the source code of this file.
Classes | |
| struct | utimbuf |
Functions | |
| int | my_copy (const char *from, const char *to, myf MyFlags) |
| int my_copy | ( | const char * | from, | |
| const char * | to, | |||
| myf | MyFlags | |||
| ) |
Definition at line 52 of file my_copy.c.
References utimbuf::actime, create_flag, DBUG_ASSERT, DBUG_ENTER, DBUG_PRINT, DBUG_RETURN, err, errno, IO_SIZE, utimbuf::modtime, my_close(), MY_COPYTIME, my_create(), MY_DONT_OVERWRITE_FILE, my_errno, MY_FNABP, MY_HOLD_ORIGINAL_MODES, MY_NABP, my_open(), my_read, my_stat(), MY_STAT, my_write, MYF, O_BINARY, O_SHARE, test, and VOID.
Referenced by ha_myisam::backup(), compress(), mysql_create_like_table(), prepare_for_restore(), and ha_myisam::restore().
00053 { 00054 uint Count; 00055 my_bool new_file_stat= 0; /* 1 if we could stat "to" */ 00056 int create_flag; 00057 File from_file,to_file; 00058 char buff[IO_SIZE]; 00059 MY_STAT stat_buff,new_stat_buff; 00060 DBUG_ENTER("my_copy"); 00061 DBUG_PRINT("my",("from %s to %s MyFlags %d", from, to, MyFlags)); 00062 00063 from_file=to_file= -1; 00064 DBUG_ASSERT(!(MyFlags & (MY_FNABP | MY_NABP))); /* for my_read/my_write */ 00065 if (MyFlags & MY_HOLD_ORIGINAL_MODES) /* Copy stat if possible */ 00066 new_file_stat= test(my_stat((char*) to, &new_stat_buff, MYF(0))); 00067 00068 if ((from_file=my_open(from,O_RDONLY | O_SHARE,MyFlags)) >= 0) 00069 { 00070 if (!my_stat(from, &stat_buff, MyFlags)) 00071 { 00072 my_errno=errno; 00073 goto err; 00074 } 00075 if (MyFlags & MY_HOLD_ORIGINAL_MODES && new_file_stat) 00076 stat_buff=new_stat_buff; 00077 create_flag= (MyFlags & MY_DONT_OVERWRITE_FILE) ? O_EXCL : O_TRUNC; 00078 00079 if ((to_file= my_create(to,(int) stat_buff.st_mode, 00080 O_WRONLY | create_flag | O_BINARY | O_SHARE, 00081 MyFlags)) < 0) 00082 goto err; 00083 00084 while ((Count=my_read(from_file,buff,IO_SIZE,MyFlags)) != 0) 00085 if (Count == (uint) -1 || 00086 my_write(to_file,buff,Count,MYF(MyFlags | MY_NABP))) 00087 goto err; 00088 00089 if (my_close(from_file,MyFlags) | my_close(to_file,MyFlags)) 00090 DBUG_RETURN(-1); /* Error on close */ 00091 00092 /* Copy modes if possible */ 00093 00094 if (MyFlags & MY_HOLD_ORIGINAL_MODES && !new_file_stat) 00095 DBUG_RETURN(0); /* File copyed but not stat */ 00096 VOID(chmod(to, stat_buff.st_mode & 07777)); /* Copy modes */ 00097 #if !defined(__WIN__) && !defined(__NETWARE__) 00098 VOID(chown(to, stat_buff.st_uid,stat_buff.st_gid)); /* Copy ownership */ 00099 #endif 00100 #if !defined(VMS) && !defined(__ZTC__) 00101 if (MyFlags & MY_COPYTIME) 00102 { 00103 struct utimbuf timep; 00104 timep.actime = stat_buff.st_atime; 00105 timep.modtime = stat_buff.st_mtime; 00106 VOID(utime((char*) to, &timep)); /* last accessed and modified times */ 00107 } 00108 #endif 00109 DBUG_RETURN(0); 00110 } 00111 00112 err: 00113 if (from_file >= 0) VOID(my_close(from_file,MyFlags)); 00114 if (to_file >= 0) VOID(my_close(to_file,MyFlags)); 00115 DBUG_RETURN(-1); 00116 } /* my_copy */
Here is the call graph for this function:

Here is the caller graph for this function:

1.4.7

