source: trunk/lib/rmdirhier.cc

Last change on this file was 1515, checked in by Peter Johansson, 9 years ago

update copyright years

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 1.7 KB
Line 
1// $Id: rmdirhier.cc 1515 2012-09-26 00:35:10Z peter $
2
3/*
4  Copyright (C) 2006 Jari Häkkinen
5  Copyright (C) 2007, 2008, 2009 Jari Häkkinen, Peter Johansson
6  Copyright (C) 2010, 2011 Peter Johansson
7
8  This file is part of svndigest, http://dev.thep.lu.se/svndigest
9
10  svndigest is free software; you can redistribute it and/or modify it
11  under the terms of the GNU General Public License as published by
12  the Free Software Foundation; either version 3 of the License, or
13  (at your option) any later version.
14
15  svndigest is distributed in the hope that it will be useful, but
16  WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  General Public License for more details.
19
20  You should have received a copy of the GNU General Public License
21  along with svndigest. If not, see <http://www.gnu.org/licenses/>.
22*/
23
24#include "rmdirhier.h"
25#include "DirectoryUtil.h"
26#include "utility.h"
27
28#include "yat/Exception.h"
29
30#include <cstdio>
31#include <cstring>
32#include <dirent.h>
33#include <fcntl.h>
34#include <iostream>
35#include <sys/stat.h>
36#include <unistd.h>
37
38
39namespace theplu {
40namespace svndigest {
41
42  void rmdirhier(const std::string& dir)
43  {
44    struct stat buf;
45    // using lstat because links should not be treated as dirs
46    lstat(dir, &buf);
47    // check if dir
48    if ((buf.st_mode & S_IFDIR)) {
49      // Delete sub-nodes
50      DirectoryUtil du(dir);
51      for (DirectoryUtil::const_iterator node=du.begin();node!=du.end();++node){
52        if ((file_name(node->path())!=".") && (file_name(node->path())!=".."))
53          rmdirhier(node->path());
54      }
55    }
56    // Make sure file is removable before removing it
57    chmod(dir.c_str(),S_IWRITE);
58    remove(dir);
59  }
60
61}} // of namespace svndigest and namespace theplu
Note: See TracBrowser for help on using the repository browser.