source: trunk/lib/CacheCopyer.cc @ 1293

Last change on this file since 1293 was 1293, checked in by Peter Johansson, 11 years ago

rewrite svndigest-copy-cache in C++. closes #463

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.0 KB
Line 
1// $Id: CacheCopyer.cc 1293 2010-11-14 05:34:10Z peter $
2
3/*
4  Copyright (C) 2010 Peter Johansson
5
6  This file is part of svndigest, http://dev.thep.lu.se/svndigest
7
8  svndigest is free software; you can redistribute it and/or modify it
9  under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 3 of the License, or
11  (at your option) any later version.
12
13  svndigest is distributed in the hope that it will be useful, but
14  WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with svndigest. If not, see <http://www.gnu.org/licenses/>.
20*/
21
22#include "CacheCopyer.h"
23
24#include "Directory.h"
25#include "File.h"
26#include "NodeVisitor.h"
27
28#include "yat/Exception.h"
29
30#include <sstream>
31#include <string>
32
33namespace theplu {
34namespace svndigest {
35
36  CacheCopyer::CacheCopyer(const std::string& target, bool verbose)
37    : NodeVisitor(), target_(target), verbose_(verbose)
38  {}
39
40
41  bool CacheCopyer::enter(Directory& dir) 
42  {
43    if (dir.ignore())
44      return false;
45
46    std::string target_dir = concatenate_path(target_, dir.local_path());
47    if (!node_exist(target_dir)) {
48      throw yat::utility::errno_error(target_dir + ": ");
49    }
50    mkdir_p(concatenate_path(target_dir, ".svndigest"));
51    return true;
52  }
53 
54
55  void CacheCopyer::leave(Directory& dir) 
56  {
57  }
58 
59
60  void CacheCopyer::visit(File& file)
61  {
62    if (file.ignore())
63      return;
64    std::string src_file = file.cache_name();
65    if (!node_exist(src_file))
66      return;
67    if (access_rights(src_file, "r"))
68      throw yat::utility::errno_error(src_file + ": ");
69    std::string target_file = 
70      concatenate_path(target_, directory_name(file.local_path()));
71    target_file = concatenate_path(target_file, 
72                                   ".svndigest/"+file_name(src_file));
73    if (verbose_)
74      std::cout << src_file << " -> " << target_file << "\n";
75    copy_file(src_file, target_file);
76  }
77
78}} // end of namespace svndigest and namespace theplu
Note: See TracBrowser for help on using the repository browser.