summaryrefslogtreecommitdiff
path: root/extra/mariabackup/backup_copy.cc
diff options
context:
space:
mode:
Diffstat (limited to 'extra/mariabackup/backup_copy.cc')
-rw-r--r--extra/mariabackup/backup_copy.cc49
1 files changed, 38 insertions, 11 deletions
diff --git a/extra/mariabackup/backup_copy.cc b/extra/mariabackup/backup_copy.cc
index 3d713776dc4..8b474c37e4b 100644
--- a/extra/mariabackup/backup_copy.cc
+++ b/extra/mariabackup/backup_copy.cc
@@ -471,6 +471,21 @@ struct datafile_cur_t {
size_t buf_size;
size_t buf_read;
size_t buf_offset;
+
+ explicit datafile_cur_t(const char* filename = NULL) :
+ file(), thread_n(0), orig_buf(NULL), buf(NULL), buf_size(0),
+ buf_read(0), buf_offset(0)
+ {
+ memset(rel_path, 0, sizeof rel_path);
+ if (filename) {
+ strncpy(abs_path, filename, sizeof abs_path);
+ abs_path[(sizeof abs_path) - 1] = 0;
+ } else {
+ abs_path[0] = '\0';
+ }
+ rel_path[0] = '\0';
+ memset(&statinfo, 0, sizeof statinfo);
+ }
};
static
@@ -489,9 +504,7 @@ datafile_open(const char *file, datafile_cur_t *cursor, uint thread_n)
{
bool success;
- memset(cursor, 0, sizeof(datafile_cur_t));
-
- strncpy(cursor->abs_path, file, sizeof(cursor->abs_path));
+ new (cursor) datafile_cur_t(file);
/* Get the relative path for the destination tablespace name, i.e. the
one that can be appended to the backup root directory. Non-system
@@ -630,11 +643,14 @@ static
int
mkdirp(const char *pathname, int Flags, myf MyFlags)
{
- char parent[PATH_MAX], *p;
+ char *parent, *p;
+ int len = strlen(pathname) + 1;
/* make a parent directory path */
- strncpy(parent, pathname, sizeof(parent));
- parent[sizeof(parent) - 1] = 0;
+ if (!(parent= (char *)malloc(len)))
+ return(-1);
+ strncpy(parent, pathname, len);
+ parent[len-1]= 0;
for (p = parent + strlen(parent);
!is_path_separator(*p) && p != parent; p--);
@@ -643,19 +659,23 @@ mkdirp(const char *pathname, int Flags, myf MyFlags)
/* try to make parent directory */
if (p != parent && mkdirp(parent, Flags, MyFlags) != 0) {
+ free(parent);
return(-1);
}
/* make this one if parent has been made */
if (my_mkdir(pathname, Flags, MyFlags) == 0) {
+ free(parent);
return(0);
}
/* if it already exists that is fine */
if (errno == EEXIST) {
+ free(parent);
return(0);
}
+ free(parent);
return(-1);
}
@@ -665,17 +685,24 @@ bool
equal_paths(const char *first, const char *second)
{
#ifdef HAVE_REALPATH
- char real_first[PATH_MAX];
- char real_second[PATH_MAX];
+ char *real_first, *real_second;
+ int result;
- if (realpath(first, real_first) == NULL) {
+ real_first = realpath(first, 0);
+ if (real_first == NULL) {
return false;
}
- if (realpath(second, real_second) == NULL) {
+
+ real_second = realpath(second, 0);
+ if (real_second == NULL) {
+ free(real_first);
return false;
}
- return (strcmp(real_first, real_second) == 0);
+ result = strcmp(real_first, real_second);
+ free(real_first);
+ free(real_second);
+ return result == 0;
#else
return strcmp(first, second) == 0;
#endif