1
/* This file is part of Strigi Desktop Search
3
* Copyright (C) 2006 Jos van den Oever <jos@vandenoever.info>
5
* This library is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU Library General Public
7
* License as published by the Free Software Foundation; either
8
* version 2 of the License, or (at your option) any later version.
10
* This library is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
* Library General Public License for more details.
15
* You should have received a copy of the GNU Library General Public License
16
* along with this library; see the file COPYING.LIB. If not, write to
17
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18
* Boston, MA 02110-1301, USA.
21
#include "../archivereader.h"
22
#include <sys/types.h>
28
using namespace Strigi;
33
test1(const char* path) {
34
FileStreamOpener opener;
36
r.addStreamOpener(&opener);
37
StreamBase<char>* s = r.openStream(path);
39
fprintf(stderr, "cannot open stream to %s\n", path);
45
test2(const char* path) {
46
FileStreamOpener opener;
48
r.addStreamOpener(&opener);
49
ArchiveReader::DirLister dl = r.dirEntries(path);
51
while (dl.nextEntry(e)) {
52
string filepath(path);
54
filepath += e.filename;
55
if (e.type == EntryInfo::File) {
56
test1(filepath.c_str());
58
test2(filepath.c_str());
63
walkdirectories(const char* path, void (*callback)(const char*)) {
64
DIR* dir = opendir(path);
70
if (p.size() > 0 && p[p.size()-1] != '/') {
73
struct dirent* subdir = readdir(dir);
76
if (subdir->d_name[0] == '.') {
77
subdir = readdir(dir);
80
string name = subdir->d_name;
81
string filepath = p + name;
82
if (lstat(filepath.c_str(), &dirstat) == 0) {
83
if (S_ISREG(dirstat.st_mode)) {
84
callback(filepath.c_str());
85
} else if (S_ISDIR(dirstat.st_mode)) {
87
walkdirectories(filepath.c_str(), callback);
90
subdir = readdir(dir);
96
* Test the class ArchiveReader by analyzing all files in the given
100
ArchiveReaderTest(int argc, char** argv) {
101
if (argc < 2) return 1;
103
walkdirectories(argv[1], test1);
104
walkdirectories(argv[1], test2);
106
fprintf(stderr, "%i errors\n", errors);