diff --git a/src/qtgui/fragbuts.cpp b/src/qtgui/fragbuts.cpp
index d688cdf6..2b1fb075 100644
--- a/src/qtgui/fragbuts.cpp
+++ b/src/qtgui/fragbuts.cpp
@@ -36,6 +36,7 @@
#include "recoll.h"
#include "debuglog.h"
#include "readfile.h"
+#include "copyfile.h"
using namespace std;
@@ -147,6 +148,12 @@ FragButs::FragButs(QWidget* parent)
m_fn = path_cat(theconfig->getConfDir(), "fragbuts.xml");
string data, reason;
+ if (access(m_fn.c_str(), 0) != 0) {
+ // config does not exist: try to create it from sample
+ string src = path_cat(theconfig->getDatadir(), "examples");
+ src = path_cat(src, "fragbuts.xml");
+ copyfile(src.c_str(), m_fn.c_str(), reason);
+ }
if (!file_to_string(m_fn, data, &reason)) {
QMessageBox::warning(0, "Recoll",
tr("%1 not found.").arg(
diff --git a/src/sampleconf/fragbuts.xml b/src/sampleconf/fragbuts.xml
index 2b3178b3..f804bef9 100644
--- a/src/sampleconf/fragbuts.xml
+++ b/src/sampleconf/fragbuts.xml
@@ -1,8 +1,14 @@
+
+
-
+
@@ -23,20 +29,29 @@
-
+
date:2010-01-01/2010-12-31
-
+
ext:cpp OR ext:cxx
-
+
dir:/my/great/directory
+
+
+
+
+
+
+
+
+
diff --git a/src/utils/copyfile.cpp b/src/utils/copyfile.cpp
index 9c93c2e5..0961072d 100644
--- a/src/utils/copyfile.cpp
+++ b/src/utils/copyfile.cpp
@@ -29,8 +29,9 @@
#include "copyfile.h"
#include "debuglog.h"
+using namespace std;
+
#define CPBSIZ 8192
-#define COPYFILE_NOERRUNLINK 1
bool copyfile(const char *src, const char *dst, string &reason, int flags)
{
@@ -38,6 +39,7 @@ bool copyfile(const char *src, const char *dst, string &reason, int flags)
int dfd = -1;
bool ret = false;
char buf[CPBSIZ];
+ int oflags = O_WRONLY|O_CREAT|O_TRUNC;
LOGDEB(("copyfile: %s to %s\n", src, dst));
@@ -46,7 +48,11 @@ bool copyfile(const char *src, const char *dst, string &reason, int flags)
goto out;
}
- if ((dfd = open(dst, O_WRONLY|O_CREAT|O_TRUNC, 0644)) < 0) {
+ if (flags & COPYFILE_EXCL) {
+ oflags |= O_EXCL;
+ }
+
+ if ((dfd = open(dst, oflags, 0644)) < 0) {
reason += string("open/creat ") + dst + ": " + strerror(errno);
// If we fail because of an open/truncate error, we do not want to unlink
// the file, we might succeed...
@@ -143,18 +149,21 @@ bool renameormove(const char *src, const char *dst, string &reason)
#include
#include
-using namespace std;
#include "copyfile.h"
+using namespace std;
+
static int op_flags;
#define OPT_MOINS 0x1
#define OPT_m 0x2
+#define OPT_e 0x4
static const char *thisprog;
static char usage [] =
"trcopyfile [-m] src dst\n"
" -m : move instead of copying\n"
+" -e : fail if dest exists (only for copy)\n"
"\n"
;
static void
@@ -177,6 +186,7 @@ int main(int argc, const char **argv)
while (**argv)
switch (*(*argv)++) {
case 'm': op_flags |= OPT_m; break;
+ case 'e': op_flags |= OPT_e; break;
default: Usage(); break;
}
argc--; argv++;
@@ -191,7 +201,11 @@ int main(int argc, const char **argv)
if (op_flags & OPT_m) {
ret = renameormove(src.c_str(), dst.c_str(), reason);
} else {
- ret = copyfile(src.c_str(), dst.c_str(), reason);
+ int flags = 0;
+ if (op_flags & OPT_e) {
+ flags |= COPYFILE_EXCL;
+ }
+ ret = copyfile(src.c_str(), dst.c_str(), reason, flags);
}
if (!ret) {
cerr << reason << endl;
diff --git a/src/utils/copyfile.h b/src/utils/copyfile.h
index 6fdc469c..71ef8cfe 100644
--- a/src/utils/copyfile.h
+++ b/src/utils/copyfile.h
@@ -18,14 +18,23 @@
#define _COPYFILE_H_INCLUDED_
#include
-using std::string;
-enum CopyfileFlags {COPYFILE_NONE = 0, COPYFILE_NOERRUNLINK = 1};
+enum CopyfileFlags {COPYFILE_NONE = 0,
+ COPYFILE_NOERRUNLINK = 1,
+ COPYFILE_EXCL = 2,
+};
-extern bool copyfile(const char *src, const char *dst, string &reason,
+/** Copy src to dst.
+ *
+ * We destroy an existing dst except if COPYFILE_EXCL is set (or we if
+ * have no permission...).
+ * A partially copied dst is normally removed, except if COPYFILE_NOERRUNLINK
+ * is set.
+ */
+extern bool copyfile(const char *src, const char *dst, std::string &reason,
int flags = 0);
-// Try to rename, copy/unlink source if this fails (different devs)
-extern bool renameormove(const char *src, const char *dst, string &reason);
+/** Try to rename src. If this fails (different devices) copy then unlink src */
+extern bool renameormove(const char *src, const char *dst, std::string &reason);
#endif /* _COPYFILE_H_INCLUDED_ */