#29 Relative path does not work with -d option

closed-fixed
nobody
None
5
2005-12-29
2005-08-04
Nicolas Duboc
No

(I have already reported this bug to Brian privately
but the 1.2a did not
correct it. So I submit it here to be sure it is
registered somewhere.)

Hi,

With CDB enabled, the -d option with a relative path
as parameter
makes spamprobe crash :

---------------
$ mkdir spamprobe.new
$ spamprobe -d spamprobe.new import
error: unable to open database spamprobe.new/sp_words:
No such file or directory
warning: berkeley db reported error: env close: Invalid
argument (22)
caught runtime exception: unable to open words database
caught signal 11: quitting
Abandon
$
---------------

Below is a patch which fixes this bug. (I hope it
does not create new
ones. I'm neither a C++ nor a BDB expert).

I'm the Debian spamprobe package maintainer. If you
consider this
patch as correct (or provide a better fix), I will
certainly include it in
the package of v1.2a I'm currently working on.

Thanks,

--
Nicolas Duboc <nduboc@debian.org>

diff -ur spamprobe-1.2a.orig/File.cc spamprobe-1.2a/File.cc
--- spamprobe-1.2a.orig/File.cc 2005-03-24
23:03:21.000000000 +0100
+++ spamprobe-1.2a/File.cc 2005-08-03
15:19:48.331096008 +0200
@@ -127,6 +127,17 @@
}
}

+File File::basename() const
+{
+ string::size_type pos = m_path.rfind(SEPARATOR);
+ if (pos == string::npos) {
+ return File(*this);
+ } else {
+ return File(m_path.substr(pos+1));
+ }
+
+}
+
void File::makeDirectory(int mode) const
{
if (mkdir(m_path.c_str(), (mode_t)mode) != 0) {
diff -ur spamprobe-1.2a.orig/File.h spamprobe-1.2a/File.h
--- spamprobe-1.2a.orig/File.h 2005-03-24
23:03:21.000000000 +0100
+++ spamprobe-1.2a/File.h 2005-08-03 15:19:00.967296400
+0200
@@ -62,6 +62,7 @@
bool isFile() const;
bool isDirectory() const;
File parent() const;
+ File basename() const;

unsigned long getSize() const;

diff -ur spamprobe-1.2a.orig/FrequencyDBImpl_bdb.cc
spamprobe-1.2a/FrequencyDBImpl_bdb.cc
--- spamprobe-1.2a.orig/FrequencyDBImpl_bdb.cc
2005-03-29 19:21:49.000000000 +0200
+++ spamprobe-1.2a/FrequencyDBImpl_bdb.cc 2005-08-04
13:00:51.465469752 +0200
@@ -144,6 +144,15 @@
return false;
}

+ // If m_env is initialized, db_home has been set as
the parent directory of db_file
+ // so we just keep the db filename is case db_file
is a relative path
+ File db_path;
+ if (m_env) {
+ db_path = db_file.basename();
+ } else {
+ db_path = db_file;
+ }
+
// SleepyCat in their infinite wisdom decided to
change the open
// function's signature in the 4.1 release. Gee
thanks for breaking
// my code guys. That was real smart and so much
better than
@@ -151,9 +160,9 @@
// hideous ifdefs into my code.
int flags = read_only ? DB_RDONLY : DB_CREATE;
#if DB_VERSION_MAJOR >= 4 && DB_VERSION_MINOR >= 1
- ret = m_file->open(m_file, NULL,
db_file.getPath().c_str(), NULL, DB_BTREE, flags,
create_mode);
+ ret = m_file->open(m_file, NULL,
db_path.getPath().c_str(), NULL, DB_BTREE, flags,
create_mode);
#else
- ret = m_file->open(m_file,
db_file.getPath().c_str(), NULL, DB_BTREE, flags,
create_mode);
+ ret = m_file->open(m_file,
db_path.getPath().c_str(), NULL, DB_BTREE, flags,
create_mode);
#endif
if (ret != 0) {
cerr << "error: unable to open database " <<
db_file.getPath() << ": " << db_strerror(ret) << endl;

Discussion

  • Brian Burton
    Brian Burton
    2005-12-29

    • status: open --> closed-fixed
     
  • Brian Burton
    Brian Burton
    2005-12-29

    Logged In: YES
    user_id=294579

    This version has been fixed in version 1.4.