-
Notifications
You must be signed in to change notification settings - Fork 4
/
FileList.cc
82 lines (74 loc) · 1.58 KB
/
FileList.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include "FileList.h"
#include <cstdio>
#ifdef HAVE_LZO
#include "LzopFile.h"
#endif
#ifdef HAVE_ZLIB
#include "GzipFile.h"
#endif
#ifdef HAVE_BZIP2
#include "Bzip2File.h"
#endif
#ifdef HAVE_LZMA
#include "PixzFile.h"
#endif
#ifdef HAVE_ZSTD
#include "ZstdFile.h"
#endif
const FileList::OpenerList FileList::Openers(initOpeners());
FileList::OpenerList FileList::initOpeners() {
OpenFunc o[] = {
#ifdef HAVE_LZO
LzopFile::open,
#endif
#ifdef HAVE_ZLIB
GzipFile::open,
#endif
#ifdef HAVE_BZIP2
Bzip2File::open,
#endif
#ifdef HAVE_LZMA
PixzFile::open,
#endif
#ifdef HAVE_ZSTD
ZstdFile::open,
#endif
};
return OpenerList(o, o + sizeof(o)/sizeof(o[0]));
}
CompressedFile *FileList::find(const std::string& dest) {
Map::iterator found = mMap.find(dest);
if (found == mMap.end())
return 0;
return found->second;
}
void FileList::add(const std::string& source) {
CompressedFile *file = 0;
try {
OpenerList::const_iterator iter;
for (iter = Openers.begin(); iter != Openers.end(); ++iter) {
try {
file = (*iter)(source, mOpenParams);
break;
} catch (CompressedFile::FormatException& e) {
// just keep going
}
}
if (!file) {
fprintf(stderr, "Don't understand format of file %s, skipping.\n",
source.c_str());
return;
}
std::string dest("/");
dest.append(file->destName());
mMap[dest] = file;
} catch (std::runtime_error& e) {
fprintf(stderr, "Error reading file %s, skipping: %s\n",
source.c_str(), e.what());
}
}
FileList::~FileList() {
for (Map::iterator iter = mMap.begin(); iter != mMap.end(); ++iter) {
delete iter->second;
}
}