#include "bacula.h"
#include "jcr.h"
-
+#include "lib/breg.h"
ATTR *new_attr()
{
{
char *p = fname;
while (p && *p) {
- p = strchr(p, '/');
- if (p && p[1] == '/') {
- strcpy(p, p+1);
- }
- if (p) {
+ p = strpbrk(p, "/\\");
+ if (p != NULL) {
+ if (IsPathSeparator(p[1])) {
+ strcpy(p, p+1);
+ }
p++;
}
}
* every filename if a prefix is supplied.
*
*/
- if (jcr->where[0] == 0) {
+
+ if (jcr->where_bregexp) {
+ char *ret;
+ apply_bregexps(attr->fname, jcr->where_bregexp, &ret);
+ pm_strcpy(attr->ofname, ret);
+
+ if (attr->type == FT_LNKSAVED || attr->type == FT_LNK) {
+ /* Always add prefix to hard links (FT_LNKSAVED) and
+ * on user request to soft links
+ */
+
+ if ((attr->type == FT_LNKSAVED || jcr->prefix_links)) {
+ apply_bregexps(attr->lname, jcr->where_bregexp, &ret);
+ pm_strcpy(attr->olname, ret);
+
+ } else {
+ pm_strcpy(attr->olname, attr->lname);
+ }
+ }
+
+ } else if (jcr->where[0] == 0) {
pm_strcpy(attr->ofname, attr->fname);
pm_strcpy(attr->olname, attr->lname);
+
} else {
const char *fn;
int wherelen = strlen(jcr->where);
#endif
fn = attr->fname; /* take whole name */
/* Ensure where is terminated with a slash */
- if (jcr->where[wherelen-1] != '/' && fn[0] != '/') {
+ if (!IsPathSeparator(jcr->where[wherelen-1]) && !IsPathSeparator(fn[0])) {
pm_strcat(attr->ofname, "/");
}
pm_strcat(attr->ofname, fn); /* copy rest of name */
/* Always add prefix to hard links (FT_LNKSAVED) and
* on user request to soft links
*/
- if (attr->lname[0] == '/' &&
+ if (IsPathSeparator(attr->lname[0]) &&
(attr->type == FT_LNKSAVED || jcr->prefix_links)) {
pm_strcpy(attr->olname, jcr->where);
add_link = true;
#endif
fn = attr->lname; /* take whole name */
/* Ensure where is terminated with a slash */
- if (add_link && jcr->where[wherelen-1] != '/' && fn[0] != '/') {
+ if (add_link &&
+ !IsPathSeparator(jcr->where[wherelen-1]) &&
+ !IsPathSeparator(fn[0])) {
pm_strcat(attr->olname, "/");
}
pm_strcat(attr->olname, fn); /* copy rest of link */
}
}
#if defined(HAVE_WIN32)
- strip_double_slashes(attr->ofname);
- strip_double_slashes(attr->olname);
+ strip_double_slashes(attr->ofname);
+ strip_double_slashes(attr->olname);
#endif
}