Imported Upstream version 3.3.1
[debian/amanda] / recover-src / set_commands.c
index 1125364a042c6030c6f192398859fc106bfa49f4..e741287ed786230135ff8379128d8186fb1c8935 100644 (file)
@@ -69,6 +69,7 @@ set_date(
            g_printf(_("No index records for cwd on new date\n"));
            g_printf(_("Setting cwd to mount point\n"));
            disk_path = newstralloc(disk_path, "/");    /* fake it */
+           disk_tpath = newstralloc(disk_tpath, "/");  /* fake it */
            clear_dir_list();
        }
     }
@@ -165,6 +166,7 @@ set_host(
        amfree(disk_name);
        amfree(mount_point);
        amfree(disk_path);
+       amfree(disk_tpath);
        clear_dir_list();
     }
     amfree(cmd);
@@ -254,6 +256,7 @@ set_disk(
     if (server_happy())
     {
        disk_path = newstralloc(disk_path, "/");
+       disk_tpath = newstralloc(disk_tpath, "/");
        suck_dir_list_from_server();    /* get list of directory contents */
     }
     else
@@ -261,6 +264,7 @@ set_disk(
        g_printf(_("No index records for disk for specified date\n"));
        g_printf(_("If date correct, notify system administrator\n"));
        disk_path = newstralloc(disk_path, "/");        /* fake it */
+       disk_tpath = newstralloc(disk_tpath, "/");      /* fake it */
        clear_dir_list();
     }
     amfree(uqmtpt);
@@ -423,7 +427,7 @@ cd_glob(
     char *uqglob;
     int   result;
 
-    char *path_on_disk = NULL;
+    char *tpath_on_disk = NULL;
 
     if (disk_name == NULL) {
        g_printf(_("Must select disk before changing directory\n"));
@@ -455,17 +459,17 @@ cd_glob(
 
     /* convert path (assumed in cwd) to one on disk */
     if (strcmp(disk_path, "/") == 0)
-        path_on_disk = stralloc2("/", regex_path);
+        tpath_on_disk = stralloc2("/", regex_path);
     else {
-        char *clean_disk_path = clean_regex(disk_path, 0);
-        path_on_disk = vstralloc(clean_disk_path, "/", regex_path, NULL);
-        amfree(clean_disk_path);
+        char *clean_disk_tpath = clean_regex(disk_tpath, 0);
+        tpath_on_disk = vstralloc(clean_disk_tpath, "/", regex_path, NULL);
+        amfree(clean_disk_tpath);
     }
 
-    result = cd_dir(path_on_disk, uqglob, verbose);
+    result = cd_dir(tpath_on_disk, uqglob, verbose);
 
     amfree(regex_path);
-    amfree(path_on_disk);
+    amfree(tpath_on_disk);
     amfree(uqglob);
 
     return result;
@@ -482,7 +486,7 @@ cd_regex(
     int  len_uqregex;
     int  result;
 
-    char *path_on_disk = NULL;
+    char *tpath_on_disk = NULL;
 
     if (disk_name == NULL) {
        g_printf(_("Must select disk before changing directory\n"));
@@ -513,16 +517,16 @@ cd_regex(
 
     /* convert path (assumed in cwd) to one on disk */
     if (strcmp(disk_path, "/") == 0)
-        path_on_disk = stralloc2("/", uqregex);
+        tpath_on_disk = stralloc2("/", uqregex);
     else {
-        char *clean_disk_path = clean_regex(disk_path, 0);
-        path_on_disk = vstralloc(clean_disk_path, "/", regex, NULL);
-        amfree(clean_disk_path);
+        char *clean_disk_tpath = clean_regex(disk_tpath, 0);
+        tpath_on_disk = vstralloc(clean_disk_tpath, "/", regex, NULL);
+        amfree(clean_disk_tpath);
     }
 
-    result = cd_dir(path_on_disk, uq_orig_regex, verbose);
+    result = cd_dir(tpath_on_disk, uq_orig_regex, verbose);
 
-    amfree(path_on_disk);
+    amfree(tpath_on_disk);
     amfree(uqregex);
     amfree(uq_orig_regex);
 
@@ -531,9 +535,9 @@ cd_regex(
 
 int
 cd_dir(
-    char *     path_on_disk,
-    char *     default_dir,
-    int                verbose)
+    char *tpath_on_disk,
+    char *default_dir,
+    int          verbose)
 {
     char *dir = NULL;
     char *s;
@@ -543,7 +547,7 @@ cd_dir(
 
     DIR_ITEM *ditem;
 
-    if ((s = validate_regexp(path_on_disk)) != NULL) {
+    if ((s = validate_regexp(tpath_on_disk)) != NULL) {
        result = set_directory(default_dir, verbose);
        return result;
     }
@@ -553,11 +557,11 @@ cd_dir(
     for (ditem=get_dir_list(); ditem!=NULL && nb_found <= 1; 
                               ditem=get_next_dir_item(ditem))
     {
-       if (match(path_on_disk, ditem->path))
+       if (match(tpath_on_disk, ditem->tpath))
        {
-           i = strlen(ditem->path);
-           if((i > 0 && ditem->path[i-1] == '/')
-               || (i > 1 && ditem->path[i-2] == '/' && ditem->path[i-1] == '.'))
+           i = strlen(ditem->tpath);
+           if((i > 0 && ditem->tpath[i-1] == '/')
+               || (i > 1 && ditem->tpath[i-2] == '/' && ditem->tpath[i-1] == '.'))
             {   /* It is a directory */
                char *dir1, *dir2;
                nb_found++;
@@ -590,6 +594,7 @@ cd_dir(
     return result;
 }
 
+/* dir is relative to dir_path or absolute with mount_point */
 int
 set_directory(
     char *     dir,
@@ -707,6 +712,8 @@ set_directory(
     if (server_happy())
     {
        disk_path = newstralloc(disk_path, new_dir);
+       g_free(disk_tpath);
+       disk_tpath = translate_octal(g_strdup(disk_path));
        suck_dir_list_from_server();    /* get list of directory contents */
        if (verbose)
            show_directory();           /* say where we moved to */
@@ -734,11 +741,11 @@ show_directory(void)
     if (mount_point == NULL || disk_path == NULL)
         g_printf(_("Must select disk first\n"));
     else if (strcmp(mount_point, "/") == 0)
-       g_printf("%s\n", disk_path);
+       g_printf("%s\n", disk_tpath);
     else if (strcmp(disk_path, "/") == 0)
        g_printf("%s\n", mount_point);
     else
-       g_printf("%s%s\n", mount_point, disk_path);
+       g_printf("%s%s\n", mount_point, disk_tpath);
 }
 
 
@@ -821,6 +828,23 @@ set_device(
                server_name);
 }
 
+void
+set_translate(
+    char *translate)
+{
+
+    if (translate == NULL) {
+       translate_mode = TRUE;
+    } else if (strcasecmp(translate, "yes") == 0 ||
+              strcasecmp(translate, "true") == 0 ||
+              strcasecmp(translate, "on") == 0) {
+       translate_mode = TRUE;
+    } else {
+       translate_mode = FALSE;
+    }
+    suck_dir_list_from_server();       /* get list of directory contents */
+}
+
 void
 set_mode(
     int                mode)