Changeset 159 for trunk


Ignore:
Timestamp:
Aug 14, 2006, 9:39:49 PM (15 years ago)
Author:
Jari Häkkinen
Message:

Fixes #63. Moved directory tree creation up. Improved target dir checking/erasing code.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bin/svndigest.cc

    r149 r159  
    1313  svndigest is distributed in the hope that it will be useful, but
    1414  WITHOUT ANY WARRANTY; without even the implied warranty of
    15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    1616  General Public License for more details.
    1717
     
    3737#include <unistd.h>
    3838
    39 using namespace std;
     39///
     40/// @brief Check whether \a path already exists or not.
     41///
     42/// @return True if \a path exists, false otherwise.
     43///
     44bool check_target(const std::string& path)
     45{
     46  struct stat buf;
     47  return !stat(path.c_str(),&buf);
     48}
     49
    4050
    4151int main(const int argc,const char* argv[])
     
    6272  }
    6373
     74  // check if target already exists and behave appropriately
     75  std::string target_path=option->targetdir() + '/' + file_name(option->root());
     76  bool need_to_erase_target = check_target(target_path);
     77  if (need_to_erase_target && !option->force())
     78    throw std::runtime_error(std::string("svndigest: directory (") +
     79                             target_path + ") already exists");
     80
    6481  // Extract repository location
    6582  std::string repo;
     
    7491  }
    7592
     93  // build directory tree already here ... if WC is upto date with
     94  // repo an exception is thrown. This avoids several costly
     95  // statements below and will not remove a digest tree below if a
     96  // tree already exists.
     97  Directory tree(0,option->root(),"");
     98  tree.parse(option->verbose());
     99
    76100  // Retrieve commit dates.
    77101  std::vector<std::string> commit_dates;
     
    85109  }
    86110
    87   // check if target already exists and behave appropriately
    88   std::string root_path(option->targetdir()+'/'+file_name(option->root()));
    89   struct stat buf;
    90   if (!stat(root_path.c_str(),&buf))
    91     // root_path already exists
    92     if (option->force()) {
    93       // force true -> removal of root_path
     111  // remove target if needed
     112  if (need_to_erase_target) {
    94113      if (option->verbose())
    95         std::cout << "rm -rf " << root_path << "\n";
    96       rmdirhier(root_path);
    97     }
    98     else {
    99       // force false -> exit
    100       std::cerr << "\nsvndigest: " << root_path << ": directory already exists"
    101                 << std::endl;
    102       exit(-1);
    103     }
     114        std::cout << "rm -rf " << target_path << "\n";
     115      rmdirhier(target_path);
     116  }
    104117
    105118  if (!option->revisions())
    106119    GnuplotFE::instance()->set_dates(commit_dates);
    107 
    108   Directory tree(0,option->root(),"");
    109   tree.parse(option->verbose());
    110 
    111   GnuplotFE::instance()->command(string("cd '")+option->targetdir()+"'");
     120  GnuplotFE::instance()->command(std::string("cd '")+option->targetdir()+"'");
    112121  chdir(option->targetdir().c_str());
    113122  try {
     
    125134  exit(0);        // normal exit
    126135}
    127 
    128 
Note: See TracChangeset for help on using the changeset viewer.