1293 |
14 Nov 10 |
peter |
// $Id$ |
1293 |
14 Nov 10 |
peter |
2 |
|
1293 |
14 Nov 10 |
peter |
3 |
/* |
1635 |
30 Mar 23 |
peter |
Copyright (C) 2010, 2011, 2012, 2023 Peter Johansson |
1293 |
14 Nov 10 |
peter |
5 |
|
1293 |
14 Nov 10 |
peter |
This file is part of svndigest, http://dev.thep.lu.se/svndigest |
1293 |
14 Nov 10 |
peter |
7 |
|
1293 |
14 Nov 10 |
peter |
svndigest is free software; you can redistribute it and/or modify it |
1293 |
14 Nov 10 |
peter |
under the terms of the GNU General Public License as published by |
1293 |
14 Nov 10 |
peter |
the Free Software Foundation; either version 3 of the License, or |
1293 |
14 Nov 10 |
peter |
(at your option) any later version. |
1293 |
14 Nov 10 |
peter |
12 |
|
1293 |
14 Nov 10 |
peter |
svndigest is distributed in the hope that it will be useful, but |
1293 |
14 Nov 10 |
peter |
WITHOUT ANY WARRANTY; without even the implied warranty of |
1293 |
14 Nov 10 |
peter |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
1293 |
14 Nov 10 |
peter |
General Public License for more details. |
1293 |
14 Nov 10 |
peter |
17 |
|
1293 |
14 Nov 10 |
peter |
You should have received a copy of the GNU General Public License |
1293 |
14 Nov 10 |
peter |
along with svndigest. If not, see <http://www.gnu.org/licenses/>. |
1293 |
14 Nov 10 |
peter |
20 |
*/ |
1293 |
14 Nov 10 |
peter |
21 |
|
1619 |
12 Mar 23 |
peter |
22 |
#include <config.h> |
1619 |
12 Mar 23 |
peter |
23 |
|
1293 |
14 Nov 10 |
peter |
24 |
#include "CacheCopyer.h" |
1293 |
14 Nov 10 |
peter |
25 |
|
1293 |
14 Nov 10 |
peter |
26 |
#include "Directory.h" |
1293 |
14 Nov 10 |
peter |
27 |
#include "File.h" |
1293 |
14 Nov 10 |
peter |
28 |
#include "NodeVisitor.h" |
1321 |
28 Nov 10 |
peter |
29 |
#include "utility.h" |
1293 |
14 Nov 10 |
peter |
30 |
|
1293 |
14 Nov 10 |
peter |
31 |
#include "yat/Exception.h" |
1293 |
14 Nov 10 |
peter |
32 |
|
1293 |
14 Nov 10 |
peter |
33 |
#include <sstream> |
1293 |
14 Nov 10 |
peter |
34 |
#include <string> |
1293 |
14 Nov 10 |
peter |
35 |
|
1508 |
31 Aug 12 |
peter |
36 |
#include <iostream> |
1508 |
31 Aug 12 |
peter |
37 |
|
1293 |
14 Nov 10 |
peter |
38 |
namespace theplu { |
1293 |
14 Nov 10 |
peter |
39 |
namespace svndigest { |
1293 |
14 Nov 10 |
peter |
40 |
|
1293 |
14 Nov 10 |
peter |
41 |
CacheCopyer::CacheCopyer(const std::string& target, bool verbose) |
1293 |
14 Nov 10 |
peter |
42 |
: NodeVisitor(), target_(target), verbose_(verbose) |
1293 |
14 Nov 10 |
peter |
43 |
{} |
1293 |
14 Nov 10 |
peter |
44 |
|
1293 |
14 Nov 10 |
peter |
45 |
|
1508 |
31 Aug 12 |
peter |
46 |
void |
1508 |
31 Aug 12 |
peter |
47 |
CacheCopyer::copy(const std::string& src, const std::string& trg_dir) const |
1293 |
14 Nov 10 |
peter |
48 |
{ |
1508 |
31 Aug 12 |
peter |
49 |
if (!node_exist(src)) |
1508 |
31 Aug 12 |
peter |
50 |
return; |
1508 |
31 Aug 12 |
peter |
51 |
if (access_rights(src, "r")) |
1508 |
31 Aug 12 |
peter |
52 |
throw yat::utility::errno_error("'" + src + "': "); |
1508 |
31 Aug 12 |
peter |
53 |
std::string target_file = |
1508 |
31 Aug 12 |
peter |
54 |
concatenate_path(trg_dir, file_name(src)); |
1508 |
31 Aug 12 |
peter |
55 |
|
1508 |
31 Aug 12 |
peter |
56 |
if (verbose_) |
1508 |
31 Aug 12 |
peter |
57 |
std::cout << src << " -> " << target_file << "\n"; |
1508 |
31 Aug 12 |
peter |
58 |
copy_file(src, target_file); |
1508 |
31 Aug 12 |
peter |
59 |
} |
1508 |
31 Aug 12 |
peter |
60 |
|
1508 |
31 Aug 12 |
peter |
61 |
|
1508 |
31 Aug 12 |
peter |
62 |
bool CacheCopyer::enter(Directory& dir) |
1508 |
31 Aug 12 |
peter |
63 |
{ |
1449 |
22 Dec 11 |
peter |
64 |
if (dir.svndigest_ignore() && dir.svncopyright_ignore()) |
1293 |
14 Nov 10 |
peter |
65 |
return false; |
1293 |
14 Nov 10 |
peter |
66 |
|
1293 |
14 Nov 10 |
peter |
67 |
std::string target_dir = concatenate_path(target_, dir.local_path()); |
1293 |
14 Nov 10 |
peter |
68 |
if (!node_exist(target_dir)) { |
1293 |
14 Nov 10 |
peter |
69 |
throw yat::utility::errno_error(target_dir + ": "); |
1293 |
14 Nov 10 |
peter |
70 |
} |
1293 |
14 Nov 10 |
peter |
71 |
mkdir_p(concatenate_path(target_dir, ".svndigest")); |
1293 |
14 Nov 10 |
peter |
72 |
return true; |
1293 |
14 Nov 10 |
peter |
73 |
} |
1293 |
14 Nov 10 |
peter |
74 |
|
1508 |
31 Aug 12 |
peter |
75 |
|
1508 |
31 Aug 12 |
peter |
76 |
void CacheCopyer::leave(Directory& dir) |
1293 |
14 Nov 10 |
peter |
77 |
{ |
1293 |
14 Nov 10 |
peter |
78 |
} |
1293 |
14 Nov 10 |
peter |
79 |
|
1508 |
31 Aug 12 |
peter |
80 |
|
1293 |
14 Nov 10 |
peter |
81 |
void CacheCopyer::visit(File& file) |
1293 |
14 Nov 10 |
peter |
82 |
{ |
1449 |
22 Dec 11 |
peter |
83 |
if (file.svndigest_ignore() && file.svncopyright_ignore()) |
1293 |
14 Nov 10 |
peter |
84 |
return; |
1293 |
14 Nov 10 |
peter |
85 |
std::string src_file = file.cache_name(); |
1508 |
31 Aug 12 |
peter |
86 |
|
1508 |
31 Aug 12 |
peter |
87 |
std::string target_dir = |
1508 |
31 Aug 12 |
peter |
88 |
concatenate_path(target_, |
1508 |
31 Aug 12 |
peter |
89 |
directory_name(file.local_path())+"/.svndigest"); |
1508 |
31 Aug 12 |
peter |
90 |
|
1508 |
31 Aug 12 |
peter |
91 |
if (!file.svndigest_ignore()) |
1508 |
31 Aug 12 |
peter |
92 |
copy(src_file, target_dir); |
1508 |
31 Aug 12 |
peter |
93 |
|
1508 |
31 Aug 12 |
peter |
94 |
replace(src_file, "svndigest-cache", "svncopyright-cache"); |
1508 |
31 Aug 12 |
peter |
95 |
if (!file.svncopyright_ignore()) |
1508 |
31 Aug 12 |
peter |
96 |
copy(src_file, target_dir); |
1508 |
31 Aug 12 |
peter |
97 |
|
1293 |
14 Nov 10 |
peter |
98 |
} |
1293 |
14 Nov 10 |
peter |
99 |
|
1293 |
14 Nov 10 |
peter |
100 |
}} // end of namespace svndigest and namespace theplu |