MCPcopy Index your code
hub / github.com/RsyncProject/rsync / copy_valid_path

Function copy_valid_path

backup.c:61–154  ·  view source on GitHub ↗

Create a backup path from the given fname, putting the result into * backup_dir_buf. Any new directories (compared to the prior backup * path) are ensured to exist as directories, replacing anything else * that may be in the way (e.g. a symlink). */

Source from the content-addressed store, hash-verified

59 * path) are ensured to exist as directories, replacing anything else
60 * that may be in the way (e.g. a symlink). */
61static BOOL copy_valid_path(const char *fname)
62{
63 const char *f;
64 int val;
65 BOOL ret = True;
66 stat_x sx;
67 char *b, *rel = backup_dir_buf + backup_dir_len, *name = rel;
68
69 for (f = fname, b = rel; *f && *f == *b; f++, b++) {
70 if (*b == '/')
71 name = b + 1;
72 }
73
74 if (stringjoin(rel, backup_dir_remainder, fname, backup_suffix, NULL) >= backup_dir_remainder) {
75 rprintf(FERROR, "backup filename too long\n");
76 *name = '\0';
77 return False;
78 }
79
80 for ( ; ; name = b + 1) {
81 if ((b = strchr(name, '/')) == NULL)
82 return True;
83 *b = '\0';
84
85 val = validate_backup_dir();
86 if (val == 0)
87 break;
88 if (val < 0) {
89 *name = '\0';
90 return False;
91 }
92
93 *b = '/';
94 }
95
96 init_stat_x(&sx);
97
98 for ( ; b; name = b + 1, b = strchr(name, '/')) {
99 *b = '\0';
100
101 while (do_mkdir_at(backup_dir_buf, ACCESSPERMS) < 0) {
102 if (errno == EEXIST) {
103 val = validate_backup_dir();
104 if (val > 0)
105 break;
106 if (val == 0)
107 continue;
108 } else
109 rsyserr(FERROR, errno, "backup mkdir %s failed", backup_dir_buf);
110 *name = '\0';
111 ret = False;
112 goto cleanup;
113 }
114
115 /* Try to transfer the directory settings of the actual dir
116 * that the files are coming from. */
117 if (x_stat(rel, &sx.st, NULL) < 0)
118 rsyserr(FERROR, errno, "backup stat %s failed", full_fname(rel));

Callers 1

get_backup_nameFunction · 0.85

Calls 15

stringjoinFunction · 0.85
validate_backup_dirFunction · 0.85
init_stat_xFunction · 0.85
do_mkdir_atFunction · 0.85
x_statFunction · 0.85
full_fnameFunction · 0.85
make_fileFunction · 0.85
get_aclFunction · 0.85
cache_tmp_aclFunction · 0.85
get_xattrFunction · 0.85
cache_tmp_xattrFunction · 0.85
set_file_attrsFunction · 0.85

Tested by

no test coverage detected