Ignore:
Location:
tags/release-0.5/bin
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • tags/release-0.5/bin/Makefile.am

    r1638 r1638  
    2828noinst_HEADERS = Parameter.h
    2929
    30 LDADD = @top_srcdir@/lib/libsvndigest.a -L$(APR_PATH)/lib -L$(SVN_PATH)/lib \
    31   -lsvn_client-1 -lsvn_diff-1 -lsvn_wc-1 -lsvn_ra-1 -lsvn_subr-1 -lapr-0
     30LDADD =  $(STATICFLAG) @top_srcdir@/lib/libsvndigest.la
    3231
    33 INCLUDES = -I@top_srcdir@/lib \
    34   -I$(SVN_PATH)/include/subversion-1 -I$(APR_PATH)/include/apr-0
     32AM_CPPFLAGS = -I@top_srcdir@/lib
    3533
    3634clean-local:
  • tags/release-0.5/bin/Parameter.cc

    r1638 r1638  
    3737  {
    3838    defaults();
    39     for (int i=1; i<argc; i++) {
     39    for (int i=1; i<argc; ++i) {
    4040      bool ok=false;
    4141      std::string myargv(argv[i]);
     
    7272          exit(0);
    7373      }
     74      else if (myargv=="-vf" || myargv=="-fv"){
     75          verbose_=true;
     76          force_=true;
     77          ok=true;
     78      }
    7479
    7580      if (!ok)
     
    8489  void Parameter::analyse(void)
    8590  {
    86     // making root absolute
    87     std::string workdir(pwd());
    88     chdir(root_.c_str());
     91    using namespace std;
     92
     93    string workdir(pwd()); // remember current working directory (cwd).
     94
     95    // Checking that root_ exists and retrieve the absolute path to root_
     96    if (chdir(root_.c_str()))
     97      throw runtime_error(string("svndigest: Root directory (") + root_ +
     98                          ") access failed.");
    8999    root_ = pwd();
    90     // remove trailing '/'
    91     if (*root_.rbegin()=='/')
    92       root_.erase(root_.begin()+root_.size()-1);
    93     chdir(workdir.c_str());
    94100
    95     // making targetdir absolute
    96     chdir(targetdir_.c_str());
     101    // need to get back to cwd if relative paths are used.
     102    if (chdir(workdir.c_str()))
     103      runtime_error(string("svndigest: Failed to access cwd: ") + workdir);
     104
     105    // Checking that targetdir_ exists and retrieve the absolute path
     106    // to targetdir_
     107    if (chdir(targetdir_.c_str()))
     108      throw runtime_error(string("svndigest: Target directory (") + targetdir_ +
     109                          ") access failed.");
    97110    targetdir_ = pwd();
    98     // remove trailing '/'
    99     if (*targetdir_.rbegin()=='/')
    100       root_.erase(targetdir_.begin()+targetdir_.size()-1);
    101     chdir(workdir.c_str());
     111    // Checking write permissions for targetdir_
     112    if (access_rights(targetdir_,"w"))
     113      throw runtime_error(string("svndigest: No write permission on target ") +
     114                                 "directory (" + targetdir_ +").");
    102115
    103     struct stat buf;
    104     // check that root directory exists
    105     if (stat(root_.c_str(),&buf))
    106       throw std::runtime_error("\nsvndigest: " + root_ + ": No such directory.");
    107 
    108     // check that target directory exists
    109     if (stat(targetdir_.c_str(),&buf)){
    110       throw std::runtime_error("\nsvndigest: " + targetdir_ +
    111                                ": No such directory.");
    112     }
    113 
     116    // return back to cwd
     117    if (chdir(workdir.c_str()))
     118      runtime_error(string("svndigest: Failed to access cwd: ") + workdir);
    114119  }
    115120
  • tags/release-0.5/bin/Parameter.h

    r1638 r1638  
     1#ifndef _theplu_svndigest_parameter_
     2#define _theplu_svndigest_parameter_
     3
    14// $Id$
    25
     
    2124  02111-1307, USA.
    2225*/
    23 
    24 #ifndef _theplu_svndigest_parameter_
    25 #define _theplu_svndigest_parameter_
    2626
    2727#include <string>
  • tags/release-0.5/bin/svndigest.cc

    r1638 r1638  
    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
     
    2626#include "Directory.h"
    2727#include "GnuplotFE.h"
     28#include "html_utility.h"
    2829#include "rmdirhier.h"
    2930#include "SVN.h"
     
    3738#include <unistd.h>
    3839
    39 using namespace std;
     40///
     41/// @brief Check whether \a path already exists or not.
     42///
     43/// @return True if \a path exists, false otherwise.
     44///
     45bool check_target(const std::string& path)
     46{
     47  struct stat buf;
     48  return !stat(path.c_str(),&buf);
     49}
     50
    4051
    4152int main(const int argc,const char* argv[])
     
    6273  }
    6374
     75  // check if target already exists and behave appropriately
     76  std::string target_path=option->targetdir() + '/' + file_name(option->root());
     77  bool need_to_erase_target = check_target(target_path);
     78  if (need_to_erase_target && !option->force())
     79    throw std::runtime_error(std::string("svndigest: directory (") +
     80                             target_path + ") already exists");
     81
    6482  // Extract repository location
    6583  std::string repo;
     
    7492  }
    7593
     94  // build directory tree already here ... if WC is upto date with
     95  // repo an exception is thrown. This avoids several costly
     96  // statements below and will not remove a digest tree below if a
     97  // tree already exists.
     98  Directory tree(0,option->root(),"");
     99  tree.parse(option->verbose());
     100
    76101  // Retrieve commit dates.
    77102  std::vector<std::string> commit_dates;
     
    85110  }
    86111
    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
     112  // remove target if needed
     113  if (need_to_erase_target) {
    94114      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     }
     115        std::cout << "rm -rf " << target_path << "\n";
     116      rmdirhier(target_path);
     117  }
    104118
    105119  if (!option->revisions())
    106120    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()+"'");
     121  GnuplotFE::instance()->command(std::string("cd '")+option->targetdir()+"'");
    112122  chdir(option->targetdir().c_str());
    113123  try {
     
    125135  exit(0);        // normal exit
    126136}
    127 
    128 
Note: See TracChangeset for help on using the changeset viewer.