1423 |
16 Dec 11 |
peter |
// $Id$ |
1423 |
16 Dec 11 |
peter |
2 |
|
1423 |
16 Dec 11 |
peter |
3 |
/* |
1635 |
30 Mar 23 |
peter |
Copyright (C) 2011, 2015, 2023 Peter Johansson |
1423 |
16 Dec 11 |
peter |
5 |
|
1423 |
16 Dec 11 |
peter |
This file is part of svndigest, http://dev.thep.lu.se/svndigest |
1423 |
16 Dec 11 |
peter |
7 |
|
1423 |
16 Dec 11 |
peter |
svndigest is free software; you can redistribute it and/or modify it |
1423 |
16 Dec 11 |
peter |
under the terms of the GNU General Public License as published by |
1423 |
16 Dec 11 |
peter |
the Free Software Foundation; either version 3 of the License, or |
1423 |
16 Dec 11 |
peter |
(at your option) any later version. |
1423 |
16 Dec 11 |
peter |
12 |
|
1423 |
16 Dec 11 |
peter |
svndigest is distributed in the hope that it will be useful, but |
1423 |
16 Dec 11 |
peter |
WITHOUT ANY WARRANTY; without even the implied warranty of |
1423 |
16 Dec 11 |
peter |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
1423 |
16 Dec 11 |
peter |
General Public License for more details. |
1423 |
16 Dec 11 |
peter |
17 |
|
1423 |
16 Dec 11 |
peter |
You should have received a copy of the GNU General Public License |
1423 |
16 Dec 11 |
peter |
along with svndigest. If not, see <http://www.gnu.org/licenses/>. |
1423 |
16 Dec 11 |
peter |
20 |
*/ |
1423 |
16 Dec 11 |
peter |
21 |
|
1619 |
12 Mar 23 |
peter |
22 |
#include <config.h> |
1619 |
12 Mar 23 |
peter |
23 |
|
1423 |
16 Dec 11 |
peter |
24 |
#include "CacheRemover.h" |
1423 |
16 Dec 11 |
peter |
25 |
|
1423 |
16 Dec 11 |
peter |
26 |
#include "Directory.h" |
1423 |
16 Dec 11 |
peter |
27 |
#include "DirectoryUtil.h" |
1423 |
16 Dec 11 |
peter |
28 |
#include "File.h" |
1423 |
16 Dec 11 |
peter |
29 |
#include "NodeVisitor.h" |
1423 |
16 Dec 11 |
peter |
30 |
#include "utility.h" |
1423 |
16 Dec 11 |
peter |
31 |
|
1423 |
16 Dec 11 |
peter |
32 |
#include "yat/Exception.h" |
1423 |
16 Dec 11 |
peter |
33 |
|
1423 |
16 Dec 11 |
peter |
34 |
#include <iostream> |
1423 |
16 Dec 11 |
peter |
35 |
|
1423 |
16 Dec 11 |
peter |
36 |
namespace theplu { |
1423 |
16 Dec 11 |
peter |
37 |
namespace svndigest { |
1423 |
16 Dec 11 |
peter |
38 |
|
1423 |
16 Dec 11 |
peter |
39 |
CacheRemover::CacheRemover(bool verbose, const std::string& suffix) |
1423 |
16 Dec 11 |
peter |
40 |
: verbose_(verbose), suffix_(suffix) |
1423 |
16 Dec 11 |
peter |
41 |
{} |
1423 |
16 Dec 11 |
peter |
42 |
|
1423 |
16 Dec 11 |
peter |
43 |
|
1423 |
16 Dec 11 |
peter |
44 |
bool CacheRemover::enter(Directory& dir) |
1423 |
16 Dec 11 |
peter |
45 |
{ |
1423 |
16 Dec 11 |
peter |
46 |
return true; |
1423 |
16 Dec 11 |
peter |
47 |
} |
1423 |
16 Dec 11 |
peter |
48 |
|
1423 |
16 Dec 11 |
peter |
49 |
|
1423 |
16 Dec 11 |
peter |
50 |
void CacheRemover::leave(Directory& directory) |
1423 |
16 Dec 11 |
peter |
51 |
{ |
1423 |
16 Dec 11 |
peter |
52 |
std::string cache_dir = concatenate_path(directory.path(), ".svndigest"); |
1423 |
16 Dec 11 |
peter |
53 |
if (!node_exist(cache_dir)) |
1423 |
16 Dec 11 |
peter |
54 |
return; |
1423 |
16 Dec 11 |
peter |
55 |
|
1423 |
16 Dec 11 |
peter |
56 |
std::string pattern = std::string("*") + suffix_; |
1423 |
16 Dec 11 |
peter |
57 |
DirectoryUtil dir(cache_dir); |
1423 |
16 Dec 11 |
peter |
58 |
SVN* svn=SVN::instance(); |
1423 |
16 Dec 11 |
peter |
59 |
for (DirectoryUtil::const_iterator node=dir.begin(); |
1423 |
16 Dec 11 |
peter |
60 |
node!=dir.end(); ++node) { |
1423 |
16 Dec 11 |
peter |
61 |
if (fnmatch(pattern, node->path())) { |
1423 |
16 Dec 11 |
peter |
62 |
std::string fn = |
1423 |
16 Dec 11 |
peter |
63 |
concatenate_path(directory.path(), file_name(node->path())); |
1423 |
16 Dec 11 |
peter |
// chop off suffix_ |
1423 |
16 Dec 11 |
peter |
65 |
fn.resize(fn.size()-suffix_.size()); |
1423 |
16 Dec 11 |
peter |
66 |
if (svn->version_controlled(fn)==SVN::unversioned) { |
1423 |
16 Dec 11 |
peter |
67 |
remove(node->path()); |
1423 |
16 Dec 11 |
peter |
68 |
if (verbose_) |
1423 |
16 Dec 11 |
peter |
69 |
std::cout << "Removing '" << node->path() << "'\n"; |
1423 |
16 Dec 11 |
peter |
70 |
} |
1423 |
16 Dec 11 |
peter |
71 |
} |
1423 |
16 Dec 11 |
peter |
72 |
} |
1423 |
16 Dec 11 |
peter |
73 |
DirectoryUtil dir2(cache_dir); |
1571 |
05 Feb 15 |
peter |
// remove cache dir if it's empty and unversioned |
1571 |
05 Feb 15 |
peter |
75 |
if (dir2.empty() && svn->version_controlled(cache_dir)==SVN::unversioned) |
1423 |
16 Dec 11 |
peter |
76 |
remove(cache_dir); |
1423 |
16 Dec 11 |
peter |
77 |
} |
1423 |
16 Dec 11 |
peter |
78 |
|
1423 |
16 Dec 11 |
peter |
79 |
|
1423 |
16 Dec 11 |
peter |
80 |
void CacheRemover::visit(File& file) |
1423 |
16 Dec 11 |
peter |
81 |
{ |
1423 |
16 Dec 11 |
peter |
// do nothing |
1423 |
16 Dec 11 |
peter |
83 |
} |
1423 |
16 Dec 11 |
peter |
84 |
|
1423 |
16 Dec 11 |
peter |
85 |
}} // end of namespace svndigest and namespace theplu |