        jcr->cached_path = NULL;
 Index: patches/testing/breg.c
 ===================================================================
---- patches/testing/breg.c	(rvision 4483)
+--- patches/testing/breg.c	(rvision 4510)
 +++ patches/testing/breg.c	(copie de travail)
-@@ -52,9 +52,6 @@
-       return NULL;
-    }
- 
--   static int _start[RE_NREGS];
--   static int _end[RE_NREGS];
--
-    self->result = get_pool_memory(PM_FNAME);
-    self->result[0] = '\0';
- 
-@@ -102,15 +99,20 @@
- 
- /* Apply all regexps to fname
-  */
--char *apply_bregexps(const char *fname, alist *bregexps)
-+bool apply_bregexps(const char *fname, alist *bregexps, char **result)
- {
-    BREGEXP *elt;
-+   bool ok=false;
-+
-    char *ret = (char *) fname;
-    foreach_alist(elt, bregexps) {
-       ret = elt->replace(ret);
-+      ok = ok || elt->success;
-    }
-    Dmsg2(500, "bregexp: fname=%s ret=%s\n", fname, ret);
--   return ret;
-+
-+   *result = ret;
-+   return ok;
- }
- 
- /* return an alist of BREGEXP or return NULL if it's not a 
-@@ -149,7 +151,7 @@
-    if (!(sep == '!' || 
- 	 sep == ':' || 
- 	 sep == ';' || 
--	 sep == '' || 
-+	 sep == '|' || 
- 	 sep == ',' || 
- 	 sep == '&' || 
- 	 sep == '%' || 
-@@ -163,7 +165,6 @@
-    char *search = (char *) motif + 1;
-    int options = REG_EXTENDED | REG_NEWLINE;
-    bool ok = false;
--   bool found_motif = false;
- 
-    /* extract 1st part */
-    char *dest = expr = bstrdup(motif);
-@@ -234,6 +235,7 @@
- /* return regexp->result */
- char *BREGEXP::replace(const char *fname)
- {
-+   success = false;		/* use this.success to known if it's ok */
-    int flen = strlen(fname);
-    int rc = re_search(&preg, (BREGEX_CAST char*) fname, flen, 0, flen, &regs);
- 
-@@ -247,7 +249,7 @@
-    if (len) {
-       result = check_pool_memory_size(result, len);
-       edit_subst(fname, &regs);
--
-+      success = true;
-       Dmsg2(500, "bregexp: len = %i, result_len = %i\n", len, strlen(result));
- 
-    } else {			/* error in substitution */
-Index: patches/testing/bregtest.c
-===================================================================
---- patches/testing/bregtest.c	(rvision 4472)
-+++ patches/testing/bregtest.c	(copie de travail)
-@@ -135,7 +135,7 @@
- 
-    while (fgets(data, sizeof(data)-1, fd)) {
-       strip_trailing_newline(data);
--      p = apply_bregexps(data, list);
-+      apply_bregexps(data, list, &p);
-       printf("%s => %s\n", data, p);
-    }
-    fclose(fd);
-Index: patches/testing/breg.h
-===================================================================
---- patches/testing/breg.h	(rvision 4472)
-+++ patches/testing/breg.h	(copie de travail)
-@@ -60,7 +60,9 @@
- class BREGEXP {
- public:
-    POOLMEM *result;		/* match result */
--   char *replace(const char *fname);
-+   bool success;		/* match is ok */
-+
-+   char *replace(const char *fname); /* return this.result */
-    void debug();
- 
-    /* private */
-@@ -90,7 +92,8 @@
- /* fill an alist with BREGEXP from where */
- alist *get_bregexps(const char *where);
- 
--char *apply_bregexps(const char *fname, alist *bregexps);
-+/* apply every regexps from the alist */
-+bool apply_bregexps(const char *fname, alist *bregexps, char **result);
- 
- /* foreach_alist free RUNSCRIPT */
- void free_bregexps(alist *bregexps); /* you have to free alist */
+@@ -393,19 +393,19 @@
+ 
+    *str_tmp = *ret = '\0';
+    
+-   if (*strip_prefix) {
++   if (strip_prefix) {
+       len += bsnprintf(ret, str_size - len, "!%s!!",
+ 		       bregexp_escape_string(str_tmp, strip_prefix, sep));
+    }
+ 
+-   if (*add_suffix) {
++   if (add_suffix) {
+       if (len) ret[len++] = ',';
+ 
+       len += bsnprintf(ret + len,  str_size - len, "!([^/])$!$1%s!",
+ 		       bregexp_escape_string(str_tmp, add_suffix, sep));
+    }
+ 
+-   if (*add_prefix) {
++   if (add_prefix) {
+       if (len) ret[len++] = ',';
+ 
+       len += bsnprintf(ret + len, str_size - len, "!^!%s!", 

Index: src/filed/job.c
===================================================================
--- src/filed/job.c	(rvision 4467)
+++ src/filed/job.c	(copie de travail)
@@ -37,6 +37,8 @@
 #include "bacula.h"
 #include "filed.h"
 
+#include "lib/breg.h"
+
 #if defined(WIN32_VSS)
 #include "vss.h"
 
@@ -1601,6 +1603,7 @@
    Dmsg2(150, "Got replace %c, where=%s\n", replace, where);
    unbash_spaces(where);
    jcr->where = bstrdup(where);
+   jcr->where_bregexp = get_bregexps(where);
    free_pool_memory(where);
    jcr->replace = replace;
    jcr->prefix_links = prefix_links;

===================================================================
--- src/jcr.h	(rvision 4466)
+++ src/jcr.h	(copie de travail)
@@ -173,6 +173,8 @@
    MSGS *jcr_msgs;                    /* Copy of message resource -- actually used */
    uint32_t ClientId;                 /* Client associated with Job */
    char *where;                       /* prefix to restore files to */
+   bool where_use_regexp;             /* True if where is a bregexp */
+   alist *where_bregexp;              /* BREGEXP alist for path manipulation */
    int cached_pnl;                    /* cached path length */
    POOLMEM *cached_path;              /* cached path */
