Changeset 3613 in MondoRescue for branches/3.2/mondo/src/mondorestore


Ignore:
Timestamp:
Nov 18, 2016, 5:31:42 PM (9 years ago)
Author:
Bruno Cornec
Message:

Add function mr_getcwd and use it to allow use o dynamically allocated memory
instead of getcwd

Location:
branches/3.2/mondo/src/mondorestore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/3.2/mondo/src/mondorestore/mondo-rstr-compare.c

    r3273 r3613  
    66#include "my-stuff.h"
    77#include "mr_mem.h"
     8#include "mr_file.h"
    89#include "../common/mondostructures.h"
    910#include "../common/libmondo.h"
     
    452453  /** needs malloc *********/
    453454    char *tmp = NULL;
    454     char *cwd, *new;
     455    char *old_pwd = NULL;
    455456    char *command = NULL;
    456457    int resA = 0;
     
    459460
    460461    malloc_string(tmp);
    461     malloc_string(cwd);
    462     malloc_string(new);
    463 
    464462    assert(bkpinfo != NULL);
    465463
    466     if (getcwd(cwd, MAX_STR_LEN - 1)) {
    467         // FIXME
    468     }
     464    old_pwd = mr_getcwd();
    469465    if (chdir(bkpinfo->restore_path)) {
    470466        //FIXME
    471467    }
    472     if (getcwd(new, MAX_STR_LEN - 1)) {
    473         // FIXME
    474     }
    475468    insist_on_this_cd_number(g_current_media_number);
    476469    unlink(MONDO_CACHE"/changed.txt");
     
    478471    resA = compare_all_tarballs();
    479472    resB = compare_all_biggiefiles();
    480     if (chdir(cwd)) {
     473    if (chdir(old_pwd)) {
    481474        // FIXME
    482475    }
     476    mr_free(old_pwd);
     477
    483478    noof_changed_files = count_lines_in_file(MONDO_CACHE"/changed.txt");
    484479    if (noof_changed_files) {
     
    494489        mr_free(tmp);
    495490    }
    496 
    497     paranoid_free(cwd);
    498     paranoid_free(new);
    499 
    500491    return (resA + resB);
    501492}
     
    525516    long q;
    526517    char *tmp = NULL;
    527     char *new;
    528     char *cwd;
    529 
    530     malloc_string(new);
    531     malloc_string(cwd);
     518    char *old_pwd = NULL;
    532519
    533520  /**************************************************************************
     
    612599
    613600            log_msg(2, "calling popup_changelist_from_file()");
    614             if (getcwd(cwd, MAX_STR_LEN - 1)) {
    615                 //FIXME
    616             }
     601            old_pwd = mr_getcwd();
    617602            if (chdir(bkpinfo->restore_path)) {
    618603                // FIXME
    619604            }
    620             if (getcwd(new, MAX_STR_LEN - 1)) {
    621                 //FIXME
    622             }
    623605            popup_changelist_from_file(MONDO_CACHE"/changed.files");
    624             if (chdir(cwd)) {
     606            if (chdir(old_pwd)) {
    625607                // FIXME
    626608            }
     609            mr_free(old_pwd);
    627610            log_msg(2, "Returning from popup_changelist_from_file()");
    628611        }
     
    634617
    635618    kill_petris();
    636     paranoid_free(new);
    637     paranoid_free(cwd);
    638619    return (retval);
    639620}
  • branches/3.2/mondo/src/mondorestore/mondo-rstr-tools.c

    r3610 r3613  
    88#include "mr_mem.h"
    99#include "mr_str.h"
     10#include "mr_file.h"
    1011#include "../common/mondostructures.h"
    1112#include "../common/libmondo.h"
     
    127128FILE *fout;
    128129char *incoming = NULL;
     130char *p = NULL;
    129131char *question = NULL;
    130132
     
    10121014
    10131015char *command = NULL;
    1014 char *tmp;
     1016char *old_pwd = NULL;
    10151017char *q;
    10161018int res = 0;
     
    10191021
    10201022assert(bkpinfo != NULL);
    1021 malloc_string(tmp);
    10221023
    10231024/* If those files already exist, do not overwrite them later on */
     
    10351036        "Filelist and biggielist already recovered from media. Yay!");
    10361037} else {
    1037     if (getcwd(tmp, MAX_STR_LEN) == NULL) {
    1038         // FIXME
    1039     }
     1038    old_pwd = mr_getcwd();
    10401039    if (chdir(bkpinfo->tmpdir)) {
    10411040        // FIXME
     
    11131112    }
    11141113
    1115     if (chdir(tmp)) {
     1114    if (chdir(old_pwd)) {
    11161115        // FIXME
    11171116    }
     1117    mr_free(old_pwd);
    11181118
    11191119    if (!does_file_exist(g_biggielist_txt)) {
     
    11921192    }
    11931193
    1194     paranoid_free(tmp);
    11951194    return (filelist);
    11961195}
  • branches/3.2/mondo/src/mondorestore/mondorestore.c

    r3610 r3613  
    1111#include "my-stuff.h"
    1212#include "mr_mem.h"
     13#include "mr_file.h"
    1314#include "../common/mondostructures.h"
    1415#include "../common/libmondo.h"
     
    17461747
    17471748  /** mallco ***/
    1748     char *cwd;
    1749     char *newpath;
     1749    char *old_pwd = NULL;
     1750    char *newpath = NULL;
    17501751    char *tmp = NULL;
    17511752    assert(bkpinfo != NULL);
    17521753
    1753     malloc_string(cwd);
    1754     malloc_string(newpath);
    17551754    log_msg(2, "restore_everything() --- starting");
    17561755    g_current_media_number = 1;
    1757     if (getcwd(cwd, MAX_STR_LEN - 1)) {
    1758         // FIXME
    1759     }
     1756    old_pwd = mr_getcwd();
    17601757    mr_asprintf(tmp, "mkdir -p %s", bkpinfo->restore_path);
    17611758    run_program_and_log_output(tmp, FALSE);
     
    17661763        //FIXME
    17671764    }
    1768     if (getcwd(newpath, MAX_STR_LEN - 1)) {
    1769         // FIXME
    1770     }
     1765    newpath = mr_getcwd();
    17711766    log_msg(1, "path is now %s", newpath);
     1767    mr_free(newpath);
     1768
    17721769    log_msg(1, "restoring everything");
    17731770    if (!find_home_of_exe("petris") && !g_text_mode) {
     
    18001797        resB = restore_all_biggiefiles_from_CD(filelist);
    18011798    }
    1802     if (chdir(cwd)) {
     1799    if (chdir(old_pwd)) {
    18031800        //FIXME
    18041801    }
     1802    mr_free(old_pwd);
    18051803    if (resA + resB) {
    18061804        log_to_screen("Errors occurred while data was being restored.");
     
    18131811    kill_petris();
    18141812    log_msg(2, "restore_everything() --- leaving");
    1815     paranoid_free(cwd);
    1816     paranoid_free(newpath);
    18171813    return (resA + resB);
    18181814}
Note: See TracChangeset for help on using the changeset viewer.