aboutsummaryrefslogtreecommitdiffstats
path: root/backup.c
diff options
context:
space:
mode:
authorWayne Davison <wayned@samba.org>2007-09-23 21:03:38 +0000
committerWayne Davison <wayned@samba.org>2007-09-23 21:03:38 +0000
commite1ac7791fefaf2489d35d6e37707cc7573cade4d (patch)
tree391d61691223594f1d3e5c3ae36f1de5c44c37a4 /backup.c
parent5b3f6a273056a22d4d87ea36e108506e854100ed (diff)
downloadandroid_external_rsync-e1ac7791fefaf2489d35d6e37707cc7573cade4d.tar.gz
android_external_rsync-e1ac7791fefaf2489d35d6e37707cc7573cade4d.tar.bz2
android_external_rsync-e1ac7791fefaf2489d35d6e37707cc7573cade4d.zip
Changed make_bak_dir() to take a const char *.
Diffstat (limited to 'backup.c')
-rw-r--r--backup.c47
1 files changed, 23 insertions, 24 deletions
diff --git a/backup.c b/backup.c
index 9d3d3b2e..a92b2a68 100644
--- a/backup.c
+++ b/backup.c
@@ -92,32 +92,37 @@ static int make_simple_backup(const char *fname)
Create a directory given an absolute path, perms based upon another directory
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;
- char *rel = fullpath + backup_dir_len;
- char *end = rel + strlen(rel);
- char *p = end;
+ int len = backup_dir_len;
+ statx sx;
- while (strncmp(fullpath, "./", 2) == 0)
+ while (*fullpath == '.' && fullpath[1] == '/') {
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. */
while (1) {
- if (--p == fullpath) {
- p += strlen(p);
- goto failure;
- }
+ if (--p == fbuf)
+ return -1;
if (*p == '/') {
*p = '\0';
- if (mkdir_defmode(fullpath) == 0)
+ if (mkdir_defmode(fbuf) == 0)
break;
if (errno != ENOENT) {
rsyserr(FERROR, errno,
"make_bak_dir mkdir %s failed",
- full_fname(fullpath));
- goto failure;
+ full_fname(fbuf));
+ return -1;
}
}
}
@@ -154,7 +159,7 @@ int make_bak_dir(char *fullpath)
free_xattr(&sx);
}
#endif
- set_file_attrs(fullpath, file, NULL, NULL, 0);
+ set_file_attrs(fbuf, file, NULL, NULL, 0);
unmake_file(file);
}
}
@@ -162,20 +167,14 @@ int make_bak_dir(char *fullpath)
p += strlen(p);
if (p == end)
break;
- if (mkdir_defmode(fullpath) < 0) {
+ if (mkdir_defmode(fbuf) < 0) {
rsyserr(FERROR, errno, "make_bak_dir mkdir %s failed",
- full_fname(fullpath));
- goto failure;
+ full_fname(fbuf));
+ return -1;
}
}
- return 0;
- failure:
- while (p != end) {
- *p = '/';
- p += strlen(p);
- }
- return -1;
+ return 0;
}
/* robustly move a file, creating new directory structures if necessary */