source: trunk/lib/CacheCopyer.cc @ 1508

Last change on this file since 1508 was 1508, checked in by Peter Johansson, 7 years ago

fixes #521. copy svncopyright cache files as well.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.4 KB
Line 
1// $Id: CacheCopyer.cc 1508 2012-08-31 11:22:43Z 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#include "utility.h"
28
29#include "yat/Exception.h"
30
31#include <sstream>
32#include <string>
33
34#include <iostream>
35
36namespace theplu {
37namespace svndigest {
38
39  CacheCopyer::CacheCopyer(const std::string& target, bool verbose)
40    : NodeVisitor(), target_(target), verbose_(verbose)
41  {}
42
43
44  void
45  CacheCopyer::copy(const std::string& src, const std::string& trg_dir) const
46  {
47    if (!node_exist(src))
48      return;
49    if (access_rights(src, "r"))
50      throw yat::utility::errno_error("'" + src + "': ");
51    std::string target_file =
52      concatenate_path(trg_dir, file_name(src));
53
54    if (verbose_)
55      std::cout << src << " -> " << target_file << "\n";
56    copy_file(src, target_file);
57  }
58
59
60  bool CacheCopyer::enter(Directory& dir)
61  {
62    if (dir.svndigest_ignore() && dir.svncopyright_ignore())
63      return false;
64
65    std::string target_dir = concatenate_path(target_, dir.local_path());
66    if (!node_exist(target_dir)) {
67      throw yat::utility::errno_error(target_dir + ": ");
68    }
69    mkdir_p(concatenate_path(target_dir, ".svndigest"));
70    return true;
71  }
72
73
74  void CacheCopyer::leave(Directory& dir)
75  {
76  }
77
78
79  void CacheCopyer::visit(File& file)
80  {
81    if (file.svndigest_ignore() && file.svncopyright_ignore())
82      return;
83    std::string src_file = file.cache_name();
84
85    std::string target_dir =
86      concatenate_path(target_,
87                       directory_name(file.local_path())+"/.svndigest");
88
89    if (!file.svndigest_ignore())
90      copy(src_file, target_dir);
91
92    replace(src_file, "svndigest-cache", "svncopyright-cache");
93    if (!file.svncopyright_ignore())
94      copy(src_file, target_dir);
95
96  }
97
98}} // end of namespace svndigest and namespace theplu
Note: See TracBrowser for help on using the repository browser.