Commit e1ac7791 authored by Wayne Davison's avatar Wayne Davison

Changed make_bak_dir() to take a const char *.

parent 5b3f6a27
...@@ -92,32 +92,37 @@ static int make_simple_backup(const char *fname) ...@@ -92,32 +92,37 @@ static int make_simple_backup(const char *fname)
Create a directory given an absolute path, perms based upon another directory Create a directory given an absolute path, perms based upon another directory
path path
****************************************************************************/ ****************************************************************************/
int make_bak_dir(char *fullpath) int make_bak_dir(const char *fullpath)
{ {
statx sx; char fbuf[MAXPATHLEN], *rel, *end, *p;
struct file_struct *file; struct file_struct *file;
char *rel = fullpath + backup_dir_len; int len = backup_dir_len;
char *end = rel + strlen(rel); statx sx;
char *p = end;
while (strncmp(fullpath, "./", 2) == 0) while (*fullpath == '.' && fullpath[1] == '/') {
fullpath += 2; fullpath += 2;
len -= 2;
}
if (strlcpy(fbuf, fullpath, sizeof fbuf) >= sizeof fbuf)
return -1;
rel = fbuf + len;
end = p = rel + strlen(rel);
/* Try to find an existing dir, starting from the deepest dir. */ /* Try to find an existing dir, starting from the deepest dir. */
while (1) { while (1) {
if (--p == fullpath) { if (--p == fbuf)
p += strlen(p); return -1;
goto failure;
}
if (*p == '/') { if (*p == '/') {
*p = '\0'; *p = '\0';
if (mkdir_defmode(fullpath) == 0) if (mkdir_defmode(fbuf) == 0)
break; break;
if (errno != ENOENT) { if (errno != ENOENT) {
rsyserr(FERROR, errno, rsyserr(FERROR, errno,
"make_bak_dir mkdir %s failed", "make_bak_dir mkdir %s failed",
full_fname(fullpath)); full_fname(fbuf));
goto failure; return -1;
} }
} }
} }
...@@ -154,7 +159,7 @@ int make_bak_dir(char *fullpath) ...@@ -154,7 +159,7 @@ int make_bak_dir(char *fullpath)
free_xattr(&sx); free_xattr(&sx);
} }
#endif #endif
set_file_attrs(fullpath, file, NULL, NULL, 0); set_file_attrs(fbuf, file, NULL, NULL, 0);
unmake_file(file); unmake_file(file);
} }
} }
...@@ -162,20 +167,14 @@ int make_bak_dir(char *fullpath) ...@@ -162,20 +167,14 @@ int make_bak_dir(char *fullpath)
p += strlen(p); p += strlen(p);
if (p == end) if (p == end)
break; break;
if (mkdir_defmode(fullpath) < 0) { if (mkdir_defmode(fbuf) < 0) {
rsyserr(FERROR, errno, "make_bak_dir mkdir %s failed", rsyserr(FERROR, errno, "make_bak_dir mkdir %s failed",
full_fname(fullpath)); full_fname(fbuf));
goto failure; return -1;
} }
} }
return 0;
failure: return 0;
while (p != end) {
*p = '/';
p += strlen(p);
}
return -1;
} }
/* robustly move a file, creating new directory structures if necessary */ /* robustly move a file, creating new directory structures if necessary */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment