Changeset 1423


Ignore:
Timestamp:
Dec 16, 2011, 4:19:31 AM (9 years ago)
Author:
Peter Johansson
Message:

new classes DirectoryUtil? and CacheRemover?. remove obsoleted cache files. closes #510

Location:
trunk
Files:
4 added
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/bin/svncopyright.cc

    r1264 r1423  
    22
    33/*
    4   Copyright (C) 2010 Peter Johansson
     4  Copyright (C) 2010, 2011 Peter Johansson
    55
    66  This file is part of svndigest, http://dev.thep.lu.se/svndigest
     
    2222#include "svncopyrightParameter.h"
    2323
     24#include "lib/CacheRemover.h"
    2425#include "lib/Configuration.h"
    2526#include "lib/Directory.h"
     
    6869
    6970    update_copyright(tree, option.verbose(), option.ignore_cache());
     71    CacheRemover cache_remover(option.verbose(), ".svncopyright-cache");
     72    tree.traverse(cache_remover);
    7073  }
    7174  catch (std::runtime_error& e) {
  • trunk/bin/svndigest.cc

    r1290 r1423  
    2323#include "svndigestParameter.h"
    2424
     25#include "lib/CacheRemover.h"
    2526#include "lib/Configuration.h"
    2627#include "lib/css.h"
     
    133134                      tree.svn_info().url(), file_count);
    134135
     136    CacheRemover cache_remover(option.verbose(), ".svndigest-cache");
     137    tree.traverse(cache_remover);
    135138  }
    136139  catch (std::runtime_error& e) {
  • trunk/lib/Directory.cc

    r1290 r1423  
    2424#include "Alias.h"
    2525#include "Configuration.h"
     26#include "DirectoryUtil.h"
    2627#include "File.h"
    2728#include "html_utility.h"
     
    3940#include <iostream>
    4041#include <iterator>
    41 #include <list>
    4242#include <map>
    4343#include <sstream>
     44#include <vector>
    4445
    45 #include <cerrno> // Needed to check error state below.
    46 #include <dirent.h>
    4746#include <sys/stat.h>
    4847
     
    5150
    5251
    53   Directory::Directory(const unsigned int level, const std::string& path, 
     52  Directory::Directory(const unsigned int level, const std::string& path,
    5453                       const std::string& output, const std::string& project)
    5554    : Node(level,path,output,project)
     
    5958      output_dir_+='/';
    6059
    61     using namespace std;
    62     DIR* directory=opendir(path.c_str());    // C API from dirent.h
    63     if (!directory)
    64       throw NodeException("ERROR: opendir() failed; " + path +
    65                           " is not a directory");
    66     list<string> entries;
    67     struct dirent* entry;
    68     errno=0;  // Global variable used by C to track errors, from errno.h
    69     while ((entry=readdir(directory)))       // C API from dirent.h
    70       entries.push_back(string(entry->d_name));
    71     if (errno)
    72       throw NodeException("ERROR: readdir() failed on " + path);
    73     closedir(directory);
     60    DirectoryUtil dir(path);
    7461
    7562    SVN* svn=SVN::instance();
    76     for (list<string>::iterator i=entries.begin(); i!=entries.end(); ++i)
    77       if ((*i)!=string(".") && (*i)!=string("..") && (*i)!=string(".svn")) {
    78         string fullpath(path_+'/'+(*i));
    79         switch (svn->version_controlled(fullpath)) {
     63    for (DirectoryUtil::const_iterator i=dir.begin(); i!=dir.end(); ++i) {
     64      std::string fn = file_name(i->path());
     65      if (fn!="." && fn!=".." && fn!=".svn") {
     66        const std::string& fullpath = i->path();
     67        switch(svn->version_controlled(fullpath)) {
    8068        case SVN::uptodate:
    8169          struct stat nodestat;                // C api from sys/stat.h
     
    9179        }
    9280      }
     81    }
    9382    std::sort(daughters_.begin(), daughters_.end(), NodePtrLess());
    9483  }
  • trunk/lib/Makefile.am

    r1358 r1423  
    55# Copyright (C) 2005 Jari Häkkinen
    66# Copyright (C) 2006, 2007, 2008, 2009 Jari Häkkinen, Peter Johansson
    7 # Copyright (C) 2010 Peter Johansson
     7# Copyright (C) 2010, 2011 Peter Johansson
    88#
    99# This file is part of svndigest, http://dev.thep.lu.se/svndigest
     
    2727noinst_LIBRARIES = libsvndigest.a libsvndigest_core.a
    2828
    29 noinst_HEADERS = AddStats.h Alias.h BlameStats.h CacheCopyer.h ClassicStats.h \
     29noinst_HEADERS = AddStats.h Alias.h BlameStats.h CacheCopyer.h \
     30  CacheRemover.h ClassicStats.h \
    3031  Colors.h Commitment.h Configuration.h \
    3132  CopyrightStats.h CopyrightVisitor.h css.h \
    32   Date.h Directory.h DirectoryPrinter.h File.h FilePrinter.h \
     33  Date.h Directory.h DirectoryPrinter.h DirectoryUtil.h File.h FilePrinter.h \
    3334  first_page.h Functor.h \
    3435  Graph.h \
     
    4445libsvndigest_a_SOURCES += DirectoryPrinter.cc
    4546libsvndigest_a_SOURCES += FilePrinter.cc
    46 libsvndigest_a_SOURCES += first_page.cc 
    47 libsvndigest_a_SOURCES += Graph.cc 
     47libsvndigest_a_SOURCES += first_page.cc
     48libsvndigest_a_SOURCES += Graph.cc
    4849libsvndigest_a_SOURCES += NodePrinter.cc
    49 libsvndigest_a_SOURCES += StatsPlotter.cc 
    50 libsvndigest_a_SOURCES += SvndigestVisitor.cc 
     50libsvndigest_a_SOURCES += StatsPlotter.cc
     51libsvndigest_a_SOURCES += SvndigestVisitor.cc
    5152
    5253libsvndigest_core_a_SOURCES = AddStats.cc Alias.cc BlameStats.cc \
    53   CacheCopyer.cc ClassicStats.cc Colors.cc \
     54  CacheCopyer.cc CacheRemover.cc ClassicStats.cc Colors.cc \
    5455  Commitment.cc Configuration.cc CopyrightStats.cc CopyrightVisitor.cc \
    55   css.cc Date.cc Directory.cc File.cc \
     56  css.cc Date.cc Directory.cc DirectoryUtil.cc File.cc \
    5657  Functor.cc HtmlBuf.cc HtmlStream.cc \
    5758  html_utility.cc LineTypeParser.cc main_utility.cc Node.cc \
     
    6263  Trac.cc utility.cc Vector.cc
    6364
    64 clean-local: 
     65clean-local:
    6566  rm -rf *~
    6667
    6768all-local:
    68 
    69 
  • trunk/lib/SvndigestVisitor.cc

    r1290 r1423  
    3737
    3838
    39   bool SvndigestVisitor::enter(Directory& dir) 
     39  bool SvndigestVisitor::enter(Directory& dir)
    4040  {
    4141    if (dir.ignore())
     
    4343    return true;
    4444  }
    45  
    4645
    47   void SvndigestVisitor::leave(Directory& dir)
     46
     47  void SvndigestVisitor::leave(Directory& dir)
    4848  {
    4949    if (report_) {
     
    5454    }
    5555  }
    56  
     56
    5757
    5858  void SvndigestVisitor::visit(File& file)
     
    7070
    7171}} // end of namespace svndigest and namespace theplu
    72 
  • trunk/lib/rmdirhier.cc

    r1213 r1423  
    7676      // Make sure file is removable before removing it
    7777      chmod(dir.c_str(),S_IWRITE);
    78       if (remove(dir.c_str()))
     78      if (::remove(dir.c_str()))
    7979        throw FileDeleteError(concatenate_path(pwd(),dir));
    8080      return;
     
    9898    // Remove the directory from its parent
    9999    chdir("..");
    100     if (remove(dir.c_str()))
     100    if (::remove(dir.c_str()))
    101101      throw DirectoryDeleteError(concatenate_path(pwd(),dir));
    102102  }
  • trunk/lib/utility.cc

    r1392 r1423  
    2828
    2929#include <cassert>
    30 #include <cerrno> 
     30#include <cerrno>
    3131#include <cstdio>
    3232#include <cstdlib>
     
    307307
    308308
     309  void remove(const std::string& fn)
     310  {
     311    if (::remove(fn.c_str())) {
     312      std::string msg("remove: ");
     313      msg += fn;
     314      throw yat::utility::errno_error(msg);
     315    }
     316  }
     317
     318
    309319  void rename(const std::string& from, const std::string to)
    310320  {
  • trunk/lib/utility.h

    r1392 r1423  
    189189
    190190  /**
     191     same as C function remove but throws errno_error at failure
     192
     193     \see man remove
     194   */
     195  void remove(const std::string& fn);
     196
     197  /**
    191198     same as rename(2) but throw errno if error is encountered
    192199
     
    269276
    270277}} // end of namespace svndigest end of namespace theplu
    271 
    272 #endif
     278#endif
  • trunk/test/Makefile.am

    r1421 r1423  
    6161
    6262# tests not yet passing are listed here
    63 XFAIL_TESTS = remove_cache_test.sh
     63XFAIL_TESTS =
    6464
    6565noinst_HEADERS = Suite.h
  • trunk/test/remove_cache_test.sh

    r1421 r1423  
    4949  || exit_fail
    5050test -e toy_project/empty/.svndigest && exit_fail
    51 test -e toy_project/dir_to_be_ignored/.svndigest && exit_fail
     51test -e toy_project/dir_to_be_ignored/.svndigest || exit_fail
    5252
    5353# === testing svncopyright ===
     
    6161echo dummie > toy_project/dir_to_be_ignored/.svndigest/foo.svncopyright-cache
    6262
    63 SVNCOPYRIGHT_run 0 --root toy_project/bin --no-report
    64 test -r toy_project/bin/.svndigest/Parameter.cc.svncopyright-cache || exit_fail
     63SVNCOPYRIGHT_run 0 --root toy_project --no-report
     64test -r toy_project/bin/.svndigest/svnstat.cc.svncopyright-cache || exit_fail
    6565test -e toy_project/bin/.svndigest/foo.svncopyright-cache && exit_fail
    6666test -e toy_project/empty/.svndigest/foo.svncopyright-cache && exit_fail
     
    6868  && exit_fail
    6969test -e toy_project/empty/.svndigest && exit_fail
    70 test -e toy_project/dir_to_be_ignored/.svndigest && exit_fail
     70test -e toy_project/dir_to_be_ignored/.svndigest || exit_fail
    7171
    7272exit_success
  • trunk/yat/Makefile.am

    r1396 r1423  
    3232noinst_HEADERS += deprecate.h
    3333noinst_HEADERS += Exception.h
     34noinst_HEADERS += FileUtil.h
    3435noinst_HEADERS += Option.h
    3536noinst_HEADERS += OptionArg.h
     
    4041
    4142
    42 yat_cc_files = 
     43yat_cc_files =
    4344yat_cc_files += ColumnStream.cc
    4445yat_cc_files += CommandLine.cc
    4546yat_cc_files += Exception.cc
     47yat_cc_files += FileUtil.cc
    4648yat_cc_files += Option.cc
    4749yat_cc_files += OptionHelp.cc
Note: See TracChangeset for help on using the changeset viewer.