summaryrefslogtreecommitdiff
path: root/mysys
diff options
context:
space:
mode:
authormonty@narttu.mysql.fi <>2003-03-10 11:22:37 +0200
committermonty@narttu.mysql.fi <>2003-03-10 11:22:37 +0200
commitc43b3af78c9db45ed6901c39dbb83066c70fbd74 (patch)
treecaaf93f4311641760c5a58ab8099d7eab15c0d79 /mysys
parent8c51eb2c126c1782e2598763d516f92eec29c924 (diff)
downloadmariadb-git-c43b3af78c9db45ed6901c39dbb83066c70fbd74.tar.gz
Don't allow BACKUP TABLE to overwrite files
Fixed memory leak when replication restarts in debug mode
Diffstat (limited to 'mysys')
-rw-r--r--mysys/my_copy.c30
1 files changed, 22 insertions, 8 deletions
diff --git a/mysys/my_copy.c b/mysys/my_copy.c
index 9b02d84d063..5bc4d1d51fa 100644
--- a/mysys/my_copy.c
+++ b/mysys/my_copy.c
@@ -32,17 +32,29 @@ struct utimbuf {
#endif
- /*
- Ordinary ownership and accesstimes are copied from 'from-file'
- if MyFlags & MY_HOLD_ORIGINAL_MODES is set and to-file exists then
- the modes of to-file isn't changed
- Dont set MY_FNABP or MY_NABP bits on when calling this function !
- */
+/*
+ int my_copy(const char *from, const char *to, myf MyFlags)
+
+ NOTES
+ Ordinary ownership and accesstimes are copied from 'from-file'
+ If MyFlags & MY_HOLD_ORIGINAL_MODES is set and to-file exists then
+ the modes of to-file isn't changed
+ If MyFlags & MY_DONT_OVERWRITE_FILE is set, we will give an error
+ if the file existed.
+
+ WARNING
+ Don't set MY_FNABP or MY_NABP bits on when calling this function !
+
+ RETURN
+ 0 ok
+ # Error
+
+*/
int my_copy(const char *from, const char *to, myf MyFlags)
{
uint Count;
- int new_file_stat;
+ int new_file_stat, create_flag;
File from_file,to_file;
char buff[IO_SIZE];
struct stat stat_buff,new_stat_buff;
@@ -63,8 +75,10 @@ int my_copy(const char *from, const char *to, myf MyFlags)
}
if (MyFlags & MY_HOLD_ORIGINAL_MODES && !new_file_stat)
stat_buff=new_stat_buff;
+ create_flag= (MyFlags & MY_DONT_OVERWRITE_FILE) ? O_EXCL : O_TRUNC;
+
if ((to_file= my_create(to,(int) stat_buff.st_mode,
- O_WRONLY | O_TRUNC | O_BINARY | O_SHARE,
+ O_WRONLY | create_flag | O_BINARY | O_SHARE,
MyFlags)) < 0)
goto err;