49 |
14 Jan 06 |
jari |
// $Id$ |
49 |
14 Jan 06 |
jari |
2 |
|
84 |
13 Mar 06 |
jari |
3 |
/* |
978 |
12 Dec 09 |
peter |
Copyright (C) 2006 Jari Häkkinen |
1635 |
30 Mar 23 |
peter |
Copyright (C) 2007 Peter Johansson |
1635 |
30 Mar 23 |
peter |
Copyright (C) 2008, 2009 Jari Häkkinen, Peter Johansson |
1635 |
30 Mar 23 |
peter |
Copyright (C) 2010, 2011, 2023 Peter Johansson |
84 |
13 Mar 06 |
jari |
8 |
|
687 |
04 Aug 08 |
peter |
This file is part of svndigest, http://dev.thep.lu.se/svndigest |
84 |
13 Mar 06 |
jari |
10 |
|
149 |
12 Aug 06 |
jari |
svndigest is free software; you can redistribute it and/or modify it |
84 |
13 Mar 06 |
jari |
under the terms of the GNU General Public License as published by |
693 |
11 Sep 08 |
jari |
the Free Software Foundation; either version 3 of the License, or |
84 |
13 Mar 06 |
jari |
(at your option) any later version. |
84 |
13 Mar 06 |
jari |
15 |
|
149 |
12 Aug 06 |
jari |
svndigest is distributed in the hope that it will be useful, but |
84 |
13 Mar 06 |
jari |
WITHOUT ANY WARRANTY; without even the implied warranty of |
149 |
12 Aug 06 |
jari |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
84 |
13 Mar 06 |
jari |
General Public License for more details. |
84 |
13 Mar 06 |
jari |
20 |
|
84 |
13 Mar 06 |
jari |
You should have received a copy of the GNU General Public License |
693 |
11 Sep 08 |
jari |
along with svndigest. If not, see <http://www.gnu.org/licenses/>. |
84 |
13 Mar 06 |
jari |
23 |
*/ |
84 |
13 Mar 06 |
jari |
24 |
|
1619 |
12 Mar 23 |
peter |
25 |
#include <config.h> |
1619 |
12 Mar 23 |
peter |
26 |
|
49 |
14 Jan 06 |
jari |
27 |
#include "rmdirhier.h" |
1428 |
17 Dec 11 |
peter |
28 |
#include "DirectoryUtil.h" |
809 |
06 Aug 09 |
peter |
29 |
#include "utility.h" |
49 |
14 Jan 06 |
jari |
30 |
|
1428 |
17 Dec 11 |
peter |
31 |
#include "yat/Exception.h" |
1428 |
17 Dec 11 |
peter |
32 |
|
1213 |
09 Oct 10 |
peter |
33 |
#include <cstdio> |
823 |
25 Sep 09 |
jari |
34 |
#include <cstring> |
49 |
14 Jan 06 |
jari |
35 |
#include <dirent.h> |
49 |
14 Jan 06 |
jari |
36 |
#include <fcntl.h> |
49 |
14 Jan 06 |
jari |
37 |
#include <iostream> |
49 |
14 Jan 06 |
jari |
38 |
#include <sys/stat.h> |
49 |
14 Jan 06 |
jari |
39 |
#include <unistd.h> |
49 |
14 Jan 06 |
jari |
40 |
|
49 |
14 Jan 06 |
jari |
41 |
|
49 |
14 Jan 06 |
jari |
42 |
namespace theplu { |
149 |
12 Aug 06 |
jari |
43 |
namespace svndigest { |
49 |
14 Jan 06 |
jari |
44 |
|
1428 |
17 Dec 11 |
peter |
45 |
void rmdirhier(const std::string& dir) |
49 |
14 Jan 06 |
jari |
46 |
{ |
687 |
04 Aug 08 |
peter |
47 |
struct stat buf; |
687 |
04 Aug 08 |
peter |
// using lstat because links should not be treated as dirs |
1186 |
27 Aug 10 |
peter |
49 |
lstat(dir, &buf); |
1445 |
20 Dec 11 |
peter |
// check if dir |
1445 |
20 Dec 11 |
peter |
51 |
if ((buf.st_mode & S_IFDIR)) { |
1445 |
20 Dec 11 |
peter |
// Delete sub-nodes |
1445 |
20 Dec 11 |
peter |
53 |
DirectoryUtil du(dir); |
1445 |
20 Dec 11 |
peter |
54 |
for (DirectoryUtil::const_iterator node=du.begin();node!=du.end();++node){ |
1445 |
20 Dec 11 |
peter |
55 |
if ((file_name(node->path())!=".") && (file_name(node->path())!="..")) |
1445 |
20 Dec 11 |
peter |
56 |
rmdirhier(node->path()); |
1445 |
20 Dec 11 |
peter |
57 |
} |
687 |
04 Aug 08 |
peter |
58 |
} |
1445 |
20 Dec 11 |
peter |
// Make sure file is removable before removing it |
1445 |
20 Dec 11 |
peter |
60 |
chmod(dir.c_str(),S_IWRITE); |
1428 |
17 Dec 11 |
peter |
61 |
remove(dir); |
49 |
14 Jan 06 |
jari |
62 |
} |
49 |
14 Jan 06 |
jari |
63 |
|
149 |
12 Aug 06 |
jari |
64 |
}} // of namespace svndigest and namespace theplu |