summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/dba/dba_db2.c4
-rw-r--r--ext/dba/dba_db3.c8
-rw-r--r--ext/dba/dba_db4.c8
3 files changed, 16 insertions, 4 deletions
diff --git a/ext/dba/dba_db2.c b/ext/dba/dba_db2.c
index d544c83b8b..a8760eeb86 100644
--- a/ext/dba/dba_db2.c
+++ b/ext/dba/dba_db2.c
@@ -53,6 +53,10 @@ DBA_OPEN_FUNC(db2)
struct stat check_stat;
int s = VCWD_STAT(info->path, &check_stat);
+ if (!s && !check_stat.st_size) {
+ info->mode = DBA_TRUNC; /* force truncate */
+ }
+
type = info->mode == DBA_READER ? DB_UNKNOWN :
info->mode == DBA_TRUNC ? DB_BTREE :
s ? DB_BTREE : DB_UNKNOWN;
diff --git a/ext/dba/dba_db3.c b/ext/dba/dba_db3.c
index cfb8791a38..8d039d4819 100644
--- a/ext/dba/dba_db3.c
+++ b/ext/dba/dba_db3.c
@@ -62,9 +62,13 @@ DBA_OPEN_FUNC(db3)
struct stat check_stat;
int s = VCWD_STAT(info->path, &check_stat);
- type = info->mode == DBA_READER ? DB_UNKNOWN :
+ if (!s && !check_stat.st_size) {
+ info->mode = DBA_TRUNC; /* force truncate */
+ }
+
+ type = info->mode == DBA_READER ? DB_UNKNOWN :
info->mode == DBA_TRUNC ? DB_BTREE :
- s? DB_BTREE : DB_UNKNOWN;
+ s ? DB_BTREE : DB_UNKNOWN;
gmode = info->mode == DBA_READER ? DB_RDONLY :
(info->mode == DBA_CREAT && s) ? DB_CREATE :
diff --git a/ext/dba/dba_db4.c b/ext/dba/dba_db4.c
index 7059f5eee0..34e2af1a1f 100644
--- a/ext/dba/dba_db4.c
+++ b/ext/dba/dba_db4.c
@@ -63,9 +63,13 @@ DBA_OPEN_FUNC(db4)
struct stat check_stat;
int s = VCWD_STAT(info->path, &check_stat);
- type = info->mode == DBA_READER ? DB_UNKNOWN :
+ if (!s && !check_stat.st_size) {
+ info->mode = DBA_TRUNC; /* force truncate */
+ }
+
+ type = info->mode == DBA_READER ? DB_UNKNOWN :
info->mode == DBA_TRUNC ? DB_BTREE :
- s? DB_BTREE : DB_UNKNOWN;
+ s ? DB_BTREE : DB_UNKNOWN;
gmode = info->mode == DBA_READER ? DB_RDONLY :
(info->mode == DBA_CREAT && s) ? DB_CREATE :