Make a complete pathname for backup file and verify any new path elements. */
| 155 | |
| 156 | /* Make a complete pathname for backup file and verify any new path elements. */ |
| 157 | char *get_backup_name(const char *fname) |
| 158 | { |
| 159 | if (backup_dir) { |
| 160 | static int initialized = 0; |
| 161 | if (!initialized) { |
| 162 | int ret; |
| 163 | if (backup_dir_len > 1) |
| 164 | backup_dir_buf[backup_dir_len-1] = '\0'; |
| 165 | ret = make_path(backup_dir_buf, 0); |
| 166 | if (backup_dir_len > 1) |
| 167 | backup_dir_buf[backup_dir_len-1] = '/'; |
| 168 | if (ret < 0) |
| 169 | return NULL; |
| 170 | initialized = 1; |
| 171 | } |
| 172 | /* copy fname into backup_dir_buf while validating the dirs. */ |
| 173 | if (copy_valid_path(fname)) |
| 174 | return backup_dir_buf; |
| 175 | /* copy_valid_path() has printed an error message. */ |
| 176 | return NULL; |
| 177 | } |
| 178 | |
| 179 | if (stringjoin(backup_dir_buf, MAXPATHLEN, fname, backup_suffix, NULL) < MAXPATHLEN) |
| 180 | return backup_dir_buf; |
| 181 | |
| 182 | rprintf(FERROR, "backup filename too long\n"); |
| 183 | return NULL; |
| 184 | } |
| 185 | |
| 186 | /* Has same return codes as make_backup(). */ |
| 187 | static inline int link_or_rename(const char *from, const char *to, |
no test coverage detected