|
a/src/common/rclconfig.cpp |
|
b/src/common/rclconfig.cpp |
1 |
#ifndef lint
|
1 |
#ifndef lint
|
2 |
static char rcsid[] = "@(#$Id: rclconfig.cpp,v 1.16 2005-12-05 14:09:16 dockes Exp $ (C) 2004 J.F.Dockes";
|
2 |
static char rcsid[] = "@(#$Id: rclconfig.cpp,v 1.17 2005-12-13 12:42:59 dockes Exp $ (C) 2004 J.F.Dockes";
|
3 |
#endif
|
3 |
#endif
|
4 |
#include <unistd.h>
|
4 |
#include <unistd.h>
|
5 |
#include <stdio.h>
|
5 |
#include <stdio.h>
|
6 |
#include <errno.h>
|
6 |
#include <errno.h>
|
7 |
#include <sys/types.h>
|
7 |
#include <sys/types.h>
|
8 |
#include <sys/stat.h>
|
8 |
#include <sys/stat.h>
|
9 |
|
9 |
|
10 |
#include <iostream>
|
10 |
#include <iostream>
|
11 |
|
11 |
|
|
|
12 |
#include "pathut.h"
|
12 |
#include "rclconfig.h"
|
13 |
#include "rclconfig.h"
|
13 |
#include "pathut.h"
|
|
|
14 |
#include "conftree.h"
|
14 |
#include "conftree.h"
|
15 |
#include "debuglog.h"
|
15 |
#include "debuglog.h"
|
16 |
#include "smallut.h"
|
16 |
#include "smallut.h"
|
17 |
#include "pathut.h"
|
|
|
18 |
#include "copyfile.h"
|
17 |
#include "copyfile.h"
|
19 |
|
18 |
|
20 |
#ifndef NO_NAMESPACES
|
19 |
#ifndef NO_NAMESPACES
|
21 |
using namespace std;
|
20 |
using namespace std;
|
22 |
#endif /* NO_NAMESPACES */
|
21 |
#endif /* NO_NAMESPACES */
|
|
... |
|
... |
27 |
static bool createConfig(string &reason)
|
26 |
static bool createConfig(string &reason)
|
28 |
{
|
27 |
{
|
29 |
const char *cprefix = getenv("RECOLL_PREFIX");
|
28 |
const char *cprefix = getenv("RECOLL_PREFIX");
|
30 |
if (cprefix == 0)
|
29 |
if (cprefix == 0)
|
31 |
cprefix = RECOLL_PREFIX;
|
30 |
cprefix = RECOLL_PREFIX;
|
32 |
string prefix(cprefix);
|
|
|
33 |
path_cat(prefix, "share/recoll/examples");
|
31 |
string prefix = path_cat(cprefix, "share/recoll/examples");
|
34 |
|
32 |
|
35 |
string recolldir = path_tildexpand("~/.recoll");
|
33 |
string recolldir = path_tildexpand("~/.recoll");
|
36 |
if (mkdir(recolldir.c_str(), 0755) < 0) {
|
34 |
if (mkdir(recolldir.c_str(), 0755) < 0) {
|
37 |
reason += string("mkdir(") + recolldir + ") failed: " +
|
35 |
reason += string("mkdir(") + recolldir + ") failed: " +
|
38 |
strerror(errno);
|
36 |
strerror(errno);
|
39 |
return false;
|
37 |
return false;
|
40 |
}
|
38 |
}
|
41 |
for (int i = 0; i < ncffiles; i++) {
|
39 |
for (int i = 0; i < ncffiles; i++) {
|
42 |
string src = prefix;
|
40 |
string src = path_cat((const string&)prefix, string(configfiles[i]));
|
43 |
path_cat(src, string(configfiles[i]));
|
41 |
string dst = path_cat((const string&)recolldir, string(configfiles[i]));
|
44 |
string dst = recolldir;
|
|
|
45 |
path_cat(dst, string(configfiles[i]));
|
|
|
46 |
if (!copyfile(src.c_str(), dst.c_str(), reason)) {
|
42 |
if (!copyfile(src.c_str(), dst.c_str(), reason)) {
|
47 |
LOGERR(("Copyfile failed: %s\n", reason.c_str()));
|
43 |
LOGERR(("Copyfile failed: %s\n", reason.c_str()));
|
48 |
return false;
|
44 |
return false;
|
49 |
}
|
45 |
}
|
50 |
}
|
46 |
}
|
|
... |
|
... |
68 |
confdir = cp;
|
64 |
confdir = cp;
|
69 |
} else {
|
65 |
} else {
|
70 |
confdir = path_home();
|
66 |
confdir = path_home();
|
71 |
confdir += ".recoll/";
|
67 |
confdir += ".recoll/";
|
72 |
}
|
68 |
}
|
73 |
string cfilename = confdir;
|
69 |
string cfilename = path_cat(confdir, "recoll.conf");
|
74 |
path_cat(cfilename, "recoll.conf");
|
|
|
75 |
|
70 |
|
76 |
if (access(confdir.c_str(), 0) != 0 || access(cfilename.c_str(), 0) != 0) {
|
71 |
if (access(confdir.c_str(), 0) != 0 || access(cfilename.c_str(), 0) != 0) {
|
77 |
if (!createConfig(reason))
|
72 |
if (!createConfig(reason))
|
78 |
return;
|
73 |
return;
|
79 |
}
|
74 |
}
|
|
... |
|
... |
90 |
|
85 |
|
91 |
string mimemapfile;
|
86 |
string mimemapfile;
|
92 |
if (!conf->get("mimemapfile", mimemapfile, "")) {
|
87 |
if (!conf->get("mimemapfile", mimemapfile, "")) {
|
93 |
mimemapfile = "mimemap";
|
88 |
mimemapfile = "mimemap";
|
94 |
}
|
89 |
}
|
95 |
string mpath = confdir;
|
90 |
string mpath = path_cat(confdir, mimemapfile);
|
96 |
path_cat(mpath, mimemapfile);
|
|
|
97 |
mimemap = new ConfTree(mpath.c_str(), true);
|
91 |
mimemap = new ConfTree(mpath.c_str(), true);
|
98 |
if (mimemap == 0 ||
|
92 |
if (mimemap == 0 ||
|
99 |
(mimemap->getStatus() != ConfSimple::STATUS_RO &&
|
93 |
(mimemap->getStatus() != ConfSimple::STATUS_RO &&
|
100 |
mimemap->getStatus() != ConfSimple::STATUS_RW)) {
|
94 |
mimemap->getStatus() != ConfSimple::STATUS_RW)) {
|
101 |
reason = string("No mime map configuration file: ") + mpath +
|
95 |
reason = string("No mime map configuration file: ") + mpath +
|
|
... |
|
... |
106 |
|
100 |
|
107 |
string mimeconffile;
|
101 |
string mimeconffile;
|
108 |
if (!conf->get("mimeconffile", mimeconffile, "")) {
|
102 |
if (!conf->get("mimeconffile", mimeconffile, "")) {
|
109 |
mimeconffile = "mimeconf";
|
103 |
mimeconffile = "mimeconf";
|
110 |
}
|
104 |
}
|
111 |
mpath = confdir;
|
|
|
112 |
path_cat(mpath, mimeconffile);
|
105 |
mpath = path_cat(confdir, mimeconffile);
|
113 |
mimeconf = new ConfTree(mpath.c_str(), true);
|
106 |
mimeconf = new ConfTree(mpath.c_str(), true);
|
114 |
if (mimeconf == 0 ||
|
107 |
if (mimeconf == 0 ||
|
115 |
(mimeconf->getStatus() != ConfSimple::STATUS_RO &&
|
108 |
(mimeconf->getStatus() != ConfSimple::STATUS_RO &&
|
116 |
mimeconf->getStatus() != ConfSimple::STATUS_RW)) {
|
109 |
mimeconf->getStatus() != ConfSimple::STATUS_RW)) {
|
117 |
reason = string("No mime configuration file: ") + mpath +
|
110 |
reason = string("No mime configuration file: ") + mpath +
|
|
... |
|
... |
228 |
|
221 |
|
229 |
string cmd;
|
222 |
string cmd;
|
230 |
const char *cp;
|
223 |
const char *cp;
|
231 |
|
224 |
|
232 |
if (cp = getenv("RECOLL_FILTERSDIR")) {
|
225 |
if (cp = getenv("RECOLL_FILTERSDIR")) {
|
233 |
cmd = cp;
|
|
|
234 |
path_cat(cmd, icmd);
|
226 |
cmd = path_cat(cp, icmd);
|
235 |
if (access(cmd.c_str(), X_OK) == 0)
|
227 |
if (access(cmd.c_str(), X_OK) == 0)
|
236 |
return cmd;
|
228 |
return cmd;
|
237 |
} else if (conf->getConfParam(string("filtersdir"), cmd)) {
|
229 |
} else if (conf->getConfParam(string("filtersdir"), cmd)) {
|
238 |
path_cat(cmd, icmd);
|
230 |
cmd = path_cat(cmd, icmd);
|
239 |
if (access(cmd.c_str(), X_OK) == 0)
|
231 |
if (access(cmd.c_str(), X_OK) == 0)
|
240 |
return cmd;
|
232 |
return cmd;
|
241 |
} else {
|
233 |
} else {
|
242 |
cmd = conf->getConfDir();
|
234 |
cmd = path_cat(conf->getConfDir(), icmd);
|
243 |
path_cat(cmd, icmd);
|
|
|
244 |
if (access(cmd.c_str(), X_OK) == 0)
|
235 |
if (access(cmd.c_str(), X_OK) == 0)
|
245 |
return cmd;
|
236 |
return cmd;
|
246 |
}
|
237 |
}
|
247 |
return icmd;
|
238 |
return icmd;
|
248 |
}
|
239 |
}
|