Changeset 2713 in MondoRescue


Ignore:
Timestamp:
Feb 2, 2011, 12:35:51 PM (13 years ago)
Author:
Bruno Cornec
Message:
  • Fix #444. mondoarchive now supports inclusion/exclusion of dirs with spaces in their name. this required a syntax change for the -E/-I options where the list of dirs needs to be separated by '|' now instead of ' '.
Location:
branches/2.2.9/mondo/src/common
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.9/mondo/src/common/libmondo-cli.c

    r2698 r2713  
    277277        }
    278278        if (bkpinfo->include_paths[0]) {
    279             strcat(bkpinfo->include_paths, " ");
     279            strcat(bkpinfo->include_paths, "|");
    280280        }
    281281
     
    286286        /* Cut the flag_val['I'] in parts containing all paths to test them */
    287287        while (p != NULL) {
    288             q = strchr(p, ' ');
     288            q = strchr(p, '|');
    289289            if (q != NULL) {
    290290                *q = '\0';
     
    612612            log_to_screen("Please supply a sensible value with '-E'\n");
    613613        }
    614         mr_strcat(bkpinfo->exclude_paths, " ");
    615614        mr_asprintf(&tmp1, "%s", flag_val['E']);
    616615
     
    620619        /* Cut the flag_val['E'] in parts containing all paths to test them */
    621620        while (p != NULL) {
    622             q = strchr(p, ' ');
     621            q = strchr(p, '|');
    623622            if (q != NULL) {
    624623                *q = '\0';
     
    655654    if ((flag_set['N']) && (! bkpinfo->restore_data))       // exclude Network mounts & devices
    656655    {
    657         mr_asprintf(&psz, "%s", list_of_NETFS_mounts_only());
    658         mr_strcat(bkpinfo->exclude_paths, "%s ", psz);
    659         mr_free(psz);
     656        psz = list_of_NETFS_mounts_only();
     657        log_msg(5, "-N means we'll exclude %s", psz);
     658        if (bkpinfo->exclude_paths) {
     659            mr_strcat(bkpinfo->exclude_paths, "|%s", psz);
     660            mr_free(psz);
     661        } else {
     662            bkpinfo->exclude_paths = psz;
     663        }
    660664
    661665        if (bkpinfo->exclude_paths != NULL) {
  • branches/2.2.9/mondo/src/common/libmondo-devices-EXT.h

    r2380 r2713  
    4646extern int eject_device(char *);
    4747
    48 extern char *list_of_NETFS_devices_and_mounts();
    4948extern char *list_of_NETFS_mounts_only(void);
    5049
  • branches/2.2.9/mondo/src/common/libmondo-devices.c

    r2697 r2713  
    20162016            log_msg (4, "%s is mounted on %s and is on disk %s", DSFptr->device, DSFptr->mount_point, ndsf);
    20172017            strcat(*included_dsf_list, DSFptr->mount_point);
    2018             strcat(*included_dsf_list, " ");
     2018            strcat(*included_dsf_list, "|");
    20192019        } else {
    20202020            log_msg (4, "%s is mounted on %s and is NOT on disk %s", DSFptr->device, DSFptr->mount_point, ndsf);
    20212021            strcat(*excluded_dsf_list, DSFptr->mount_point);
    2022             strcat(*excluded_dsf_list, " ");
     2022            strcat(*excluded_dsf_list, "|");
    20232023        }
    20242024        DSFptr = DSFptr->next;
     
    20432043char *mounted_on_dsf = NULL;
    20442044char *not_mounted_on_dsf = NULL;
    2045 char token_chars[] =" \t\r\f\a\0\n";
     2045char token_chars[] ="|\t\r\f\a\0\n";
    20462046char *tmp = NULL;
    20472047char *tmp1 = NULL;
     
    20642064                log_to_screen("==> %s", mounted_on_dsf);
    20652065                log_msg (5, "Adding to bkpinfo->exclude_paths due to -E option: %s", mounted_on_dsf);
    2066                 mr_strcat(bkpinfo->exclude_paths, " %s ",mounted_on_dsf);
    2067                 mr_strcat(bkpinfo->exclude_devs, " %s ",token);
     2066                if (bkpinfo->exclude_paths) {
     2067                    mr_strcat(bkpinfo->exclude_paths,"|%s",mounted_on_dsf);
     2068                } else {
     2069                    mr_asprintf(bkpinfo->exclude_paths,"%s",mounted_on_dsf);
     2070                }
     2071                if (bkpinfo->exclude_devs) {
     2072                    mr_strcat(bkpinfo->exclude_devs,"|%s",token);
     2073                } else {
     2074                    mr_asprintf(bkpinfo->exclude_devs,"%s",token);
     2075                }
    20682076            }
    20692077        } else {
     
    20752083                log_to_screen("Not archiving the following file systems:");
    20762084                log_to_screen("==> %s", not_mounted_on_dsf);
    2077                 mr_strcat(bkpinfo->exclude_paths, " %s ", not_mounted_on_dsf);
     2085                if (bkpinfo->exclude_paths) {
     2086                    mr_strcat(bkpinfo->exclude_paths, "|%s",not_mounted_on_dsf);
     2087                } else {
     2088                    mr_asprintf(bkpinfo->exclude_paths,"%s",not_mounted_on_dsf);
     2089                }
    20782090            }
    20792091        }
     
    20852097    /* A device special file was not passed in. Process it as a path. */
    20862098    case -1:
    2087         /* we need to add a space efore and after token to be sure our strstr test works correctly */
    2088         mr_asprintf(&tmp1," %s ",token);
     2099        /*  Adds a | to ensure correct detection even at both ends */
     2100        mr_asprintf(&tmp1,"|%s",token);
    20892101        if (mode == 'E') {
    20902102            /*  Add the token if not already in the list */
    2091             mr_asprintf(&tmp," %s ",bkpinfo->exclude_paths);
     2103            mr_asprintf(&tmp,"|%s|",bkpinfo->exclude_paths);
    20922104            if (strstr(tmp,tmp1) == NULL) {
    2093                 mr_strcat(bkpinfo->exclude_paths, tmp1);
     2105                if (bkpinfo->exclude_paths) {
     2106                    mr_strcat(bkpinfo->exclude_paths,tmp1);
     2107                    mr_free(tmp1);
     2108                } else {
     2109                    bkpinfo->exclude_paths = tmp1;
     2110                }
    20942111            }
    20952112        } else {
    20962113            /*  Add the token if not already in the list */
    2097             mr_asprintf(&tmp," %s ",bkpinfo->include_paths);
     2114            mr_asprintf(&tmp,"|%s|",bkpinfo->include_paths);
    20982115            if (strstr(tmp,tmp1) == NULL) {
    2099                 strcat(bkpinfo->include_paths, tmp1);
    2100             }
     2116                strcat(bkpinfo->include_paths,tmp1);
     2117            }
     2118            mr_free(tmp1);
    21012119        }
    21022120        mr_free(tmp);
    2103         mr_free(tmp1);
    21042121        break;
    21052122    }
     
    26482665        if (!popup_and_get_string
    26492666            ("Backup paths",
    2650              "Please enter paths which you want me to backup. The default is '/' (i.e. everything).",
     2667             "Please enter paths (separated by '|') which you want me to backup. The default is '/' (i.e. everything).",
    26512668             bkpinfo->include_paths, MAX_STR_LEN)) {
    26522669            log_to_screen("User has chosen not to backup the PC");
    26532670            finish(1);
    26542671        }
    2655         mr_asprintf(&tmp, "%s", list_of_NETFS_mounts_only());
     2672        tmp = list_of_NETFS_mounts_only();
    26562673        if (strlen(tmp) > 2) {
    2657             mr_strcat(bkpinfo->exclude_paths, " %s",tmp);
     2674            mr_strcat(bkpinfo->exclude_paths, "|%s",tmp);
    26582675        }
    26592676        mr_free(tmp);
     
    26722689
    26732690        strncpy(p,bkpinfo->exclude_paths,(8*MAX_STR_LEN)-1);
    2674         popup_and_get_string("Exclude paths", "Please enter paths which you do NOT want to backup. Separate them with spaces. NB: /tmp and /proc are always excluded. :-) Just hit 'Enter' if you want to do a full system backup.", p, (8*MAX_STR_LEN)-1);
     2691        popup_and_get_string("Exclude paths", "Please enter paths which you do NOT want to backup. Separate them with '|'. NB: /tmp and /proc are always excluded. :-) Just hit 'Enter' if you want to do a full system backup.", p, (8*MAX_STR_LEN)-1);
    26752692        if (p == NULL) {
    26762693            log_to_screen("User has chosen not to backup the PC");
     
    27562773    /*  the mr_make_devlist_from_pathlist function appends
    27572774     *  to the *_paths variables so copy before */
    2758     mr_asprintf(&tmp, "%s ", bkpinfo->exclude_paths);
    2759     mr_make_devlist_from_pathlist(tmp, 'E');
    2760     mr_free(tmp);
    2761     mr_asprintf(&tmp, "%s ", bkpinfo->include_paths);
    2762     mr_make_devlist_from_pathlist(tmp, 'I');
    2763     mr_free(tmp);
     2775    mr_make_devlist_from_pathlist(bkpinfo->exclude_paths, 'E');
     2776    mr_make_devlist_from_pathlist(bkpinfo->include_paths, 'I');
    27642777
    27652778    log_it("scratchdir = '%s'", bkpinfo->scratchdir);
     
    27852798
    27862799
    2787 
    2788 
    2789 /**
    2790  * @addtogroup utilityGroup
    2791  * @{
    2792  */
    2793 /**
    2794  * Get a space-separated list of NETFS devices and mounts.
     2800/**
     2801 * Get a |-separated list of NETFS mounts.
    27952802 * @return The list created.
    2796  * @note The return value points to static data that will be overwritten with each call.
    2797  */
    2798 char *list_of_NETFS_devices_and_mounts(void)
    2799 {
    2800     char *exclude_these_devices = NULL;
     2803 * @note The return value points to allocated string that needs to be freed
     2804 * @bug Even though we only want the mounts, the devices are still checked.
     2805 */
     2806char *list_of_NETFS_mounts_only(void)
     2807{
    28012808    char *exclude_these_directories = NULL;
    2802     static char result_sz[1024];
    2803 
    2804     mr_asprintf(&exclude_these_directories,"%s",list_of_NETFS_mounts_only());
    2805     mr_asprintf(&exclude_these_devices,"%s", call_program_and_get_last_line_of_output("tr -s '\t' ' ' < /etc/fstab | grep -E '( (coda|ncpfs|sshfs|nfs|nfs4|smbfs|cifs|afs|gfs|ocfs|ocfs2|mvfs|nsspool|nsvol) )' | cut -d' ' -f1 | tr -s '\n' ' ' | awk '{print $0;}'"));
    2806     snprintf(result_sz, 1023, "%s %s", exclude_these_directories, exclude_these_devices);
    2807     mr_free(exclude_these_devices);
    2808     mr_free(exclude_these_directories);
    2809     return (result_sz);
    2810 }
    2811 
    2812 
    2813 
    2814 
    2815 /**
    2816  * Get a space-separated list of NETFS mounts.
    2817  * @return The list created.
    2818  * @note The return value points to static data that will be overwritten with each call.
    2819  * @bug Even though we only want the mounts, the devices are still checked.
    2820  */
    2821 char *list_of_NETFS_mounts_only(void)
    2822 {
    2823     char *exclude_these_directories = NULL;
    2824     static char result_sz[512];
    2825 
    2826     mr_asprintf(&exclude_these_directories,"%s", call_program_and_get_last_line_of_output("mount -t coda,ncpfs,fuse.sshfs,nfs,nfs4,smbfs,cifs,afs,gfs,ocfs,ocfs2,mvfs,nsspool,nssvol | tr -s '\t' ' ' | cut -d' ' -f3 | tr -s '\n' ' ' | awk '{print $0;}'"));
    2827     snprintf(result_sz, 511, "%s", exclude_these_directories);
    2828     mr_free(exclude_these_directories);
    2829     return (result_sz);
     2809
     2810    mr_asprintf(&exclude_these_directories,"%s", call_program_and_get_last_line_of_output("mount -t coda,ncpfs,fuse.sshfs,nfs,nfs4,smbfs,cifs,afs,gfs,ocfs,ocfs2,mvfs,nsspool,nssvol | tr -s '\t' ' ' | cut -d' ' -f3 | tr -s '\n' '|' | awk '{print $0;}'"));
     2811    log_msg(9,"list_of_NETFS_mounts_only returns %s\n",exclude_these_directories);
     2812    return(exclude_these_directories);
    28302813}
    28312814
  • branches/2.2.9/mondo/src/common/libmondo-devices.h

    r2380 r2713  
    3838int eject_device(char *);
    3939
    40 char *list_of_NETFS_devices_and_mounts();
    4140char *list_of_NETFS_mounts_only();
    4241
  • branches/2.2.9/mondo/src/common/libmondo-filelist.c

    r2711 r2713  
    12951295    mr_asprintf(&sz_res, "%s", incoming);
    12961296    p = sz_res;
    1297     while ((*p != ' ' || in_quotes) && *p != '\0') {
     1297    while ((*p != '|' || in_quotes) && *p != '\0') {
    12981298        if (*p == '\"') {
    12991299            in_quotes = !in_quotes;
     
    13261326                      time_t time_of_last_full_backup)
    13271327{
    1328     const char delims[] = " ";
     1328    const char delims[] = "|";
    13291329
    13301330    DIR *dip;
     
    13361336    static int percentage = 0;
    13371337    char *skip_these;
    1338     char *new_with_spaces;
     1338    char *new_with_pipe;
    13391339    char *strtmp;
    13401340    char *token;
     
    14341434
    14351435//  log_msg(0, "Cataloguing %s", dir);
    1436     if (sth[0] == ' ') {
    1437         mr_asprintf(&skip_these, "%s", sth);
    1438     } else {
    1439         mr_asprintf(&skip_these, " %s ", sth);
    1440     }
    1441     mr_asprintf(&new_with_spaces, " %s ", dir1);
     1436    mr_asprintf(&skip_these, "|%s|", sth);
     1437   
     1438    mr_asprintf(&new_with_pipe, "|%s|", dir1);
    14421439    if ((dip = opendir(dir1)) == NULL) {
    14431440        mr_asprintf(&tmp,"opendir %s", dir1);
    14441441        log_OS_error(tmp);
    14451442        paranoid_free(tmp);
    1446     } else if (strstr(skip_these, new_with_spaces)) {
     1443    } else if (strstr(skip_these, new_with_pipe)) {
    14471444        log_msg(10, "Found dir ***%s**** excluded", dir1);
    14481445        fprintf(fout, "%s\n", dir1);    // if excluded dir then print dir ONLY
     
    14571454                mr_asprintf(&new,"%s%s",dir1,dit->d_name);
    14581455            }
    1459             paranoid_free(new_with_spaces);
    1460             mr_asprintf(&new_with_spaces, " %s ", new);
    1461             if (strstr(skip_these, new_with_spaces)) {
     1456            paranoid_free(new_with_pipe);
     1457            mr_asprintf(&new_with_pipe, "|%s|", new);
     1458            if (strstr(skip_these, new_with_pipe)) {
    14621459                fprintf(fout, "%s\n", new);
    14631460                log_msg(10, "Found child dir ***%s**** excluded", new);
    1464                 paranoid_free(new_with_spaces);
     1461                paranoid_free(new_with_pipe);
    14651462            } else {
    1466                 paranoid_free(new_with_spaces);
     1463                paranoid_free(new_with_pipe);
    14671464                if (!lstat(new, &statbuf)) {
    14681465                    if (!S_ISLNK(statbuf.st_mode)
     
    14971494        }
    14981495    }
    1499     paranoid_free(new_with_spaces);
     1496    paranoid_free(new_with_pipe);
    15001497    paranoid_free(skip_these);
    15011498    mr_free(dir);
     
    15381535    char *p, *q;
    15391536    char *sz_datefile;
    1540     char *sz_filelist, *exclude_paths, *tmp;
     1537    char *sz_filelist, *tmp;
     1538    char *exclude_paths = NULL;
    15411539    int i;
    15421540    FILE *fout;
     
    15491547    malloc_string(tmp);
    15501548    malloc_string(g_skeleton_filelist);
    1551     if (!(exclude_paths = malloc(8*MAX_STR_LEN))) {
    1552         fatal_error("Cannot malloc exclude_paths");
    1553     }
    15541549    mr_asprintf(&sz_datefile,MONDO_CACHE"/difflevel.%d" , 0);
    15551550    if (!include_paths && !userdef_filelist) {
     
    16191614        paranoid_free(tmp1);
    16201615
    1621         snprintf(exclude_paths, (size_t)8*MAX_STR_LEN," %s %s %s %s %s . .. \
    1622 " MNT_CDROM " " MNT_FLOPPY " /media /tmp \
    1623 /proc /sys /dev/shm " MINDI_CACHE, MONDO_CACHE, excp, tmp2, (tmpdir[0] == '/' && tmpdir[1] == '/') ? (tmpdir + 1) : tmpdir, (scratchdir[0] == '/' && scratchdir[1] == '/') ? (scratchdir + 1) : scratchdir);
     1616        mr_asprintf(&exclude_paths, MONDO_CACHE"|%s|%s|%s|%s|.|..|"MNT_CDROM"|"MNT_FLOPPY"|/media|/tmp|/proc|/sys|/dev/shm|"MINDI_CACHE,excp, tmp2, (tmpdir[0] == '/' && tmpdir[1] == '/') ? (tmpdir + 1) : tmpdir, (scratchdir[0] == '/' && scratchdir[1] == '/') ? (scratchdir + 1) : scratchdir);
    16241617        paranoid_free(tmp2);
    16251618
     
    16481641                p += strlen(q);
    16491642                paranoid_free(q);
    1650                 while (*p == ' ') {
     1643                while (*p == '|') {
    16511644                    p++;
    16521645                }
Note: See TracChangeset for help on using the changeset viewer.