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, 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 <iostream> |
1423 |
16 Dec 11 |
peter |
25 |
|
1423 |
16 Dec 11 |
peter |
26 |
#include "DirectoryUtil.h" |
1423 |
16 Dec 11 |
peter |
27 |
#include "utility.h" |
1423 |
16 Dec 11 |
peter |
28 |
|
1423 |
16 Dec 11 |
peter |
29 |
#include "yat/Exception.h" |
1423 |
16 Dec 11 |
peter |
30 |
|
1423 |
16 Dec 11 |
peter |
31 |
#include <cerrno> |
1423 |
16 Dec 11 |
peter |
32 |
#include <dirent.h> |
1423 |
16 Dec 11 |
peter |
33 |
#include <sys/stat.h> |
1423 |
16 Dec 11 |
peter |
34 |
|
1423 |
16 Dec 11 |
peter |
35 |
namespace theplu { |
1423 |
16 Dec 11 |
peter |
36 |
namespace svndigest { |
1423 |
16 Dec 11 |
peter |
37 |
|
1423 |
16 Dec 11 |
peter |
38 |
DirectoryUtil::DirectoryUtil(const std::string& path) |
1423 |
16 Dec 11 |
peter |
39 |
{ |
1423 |
16 Dec 11 |
peter |
40 |
using namespace std; |
1423 |
16 Dec 11 |
peter |
41 |
DIR* directory=opendir(path.c_str()); // C API from dirent.h |
1423 |
16 Dec 11 |
peter |
42 |
if (!directory) |
1423 |
16 Dec 11 |
peter |
43 |
throw yat::utility::errno_error("opendir() failed: " + path); |
1423 |
16 Dec 11 |
peter |
44 |
struct dirent* entry; |
1423 |
16 Dec 11 |
peter |
45 |
|
1423 |
16 Dec 11 |
peter |
46 |
using yat::utility::FileUtil; |
1423 |
16 Dec 11 |
peter |
47 |
errno=0; |
1423 |
16 Dec 11 |
peter |
48 |
while ((entry=readdir(directory))) |
1423 |
16 Dec 11 |
peter |
49 |
entries_.push_back(FileUtil(concatenate_path(path, entry->d_name))); |
1423 |
16 Dec 11 |
peter |
50 |
closedir(directory); |
1423 |
16 Dec 11 |
peter |
51 |
if (errno) |
1423 |
16 Dec 11 |
peter |
52 |
throw yat::utility::errno_error("readdir() failed: " + path); |
1423 |
16 Dec 11 |
peter |
53 |
} |
1423 |
16 Dec 11 |
peter |
54 |
|
1423 |
16 Dec 11 |
peter |
55 |
|
1423 |
16 Dec 11 |
peter |
56 |
DirectoryUtil::const_iterator DirectoryUtil::begin(void) const |
1423 |
16 Dec 11 |
peter |
57 |
{ |
1423 |
16 Dec 11 |
peter |
58 |
return entries_.begin(); |
1423 |
16 Dec 11 |
peter |
59 |
} |
1423 |
16 Dec 11 |
peter |
60 |
|
1423 |
16 Dec 11 |
peter |
61 |
|
1423 |
16 Dec 11 |
peter |
62 |
bool DirectoryUtil::empty(void) const |
1423 |
16 Dec 11 |
peter |
63 |
{ |
1423 |
16 Dec 11 |
peter |
64 |
return entries_.size()==2; |
1423 |
16 Dec 11 |
peter |
65 |
} |
1423 |
16 Dec 11 |
peter |
66 |
|
1423 |
16 Dec 11 |
peter |
67 |
|
1423 |
16 Dec 11 |
peter |
68 |
DirectoryUtil::const_iterator DirectoryUtil::end(void) const |
1423 |
16 Dec 11 |
peter |
69 |
{ |
1423 |
16 Dec 11 |
peter |
70 |
return entries_.end(); |
1423 |
16 Dec 11 |
peter |
71 |
} |
1423 |
16 Dec 11 |
peter |
72 |
|
1423 |
16 Dec 11 |
peter |
73 |
}} // end of namespace svndigest and namespace theplu |