-
- die "Cannot open $ufn ($!)\n" unless $dbm;
-
- $lru = LRU->newbase("DXUser", $lrusize);
-
- # do a conversion if required
- if ($dbm && $convert) {
- my ($key, $val, $action, $count, $err) = ('','',0,0,0);
-
- my %oldu;
- dbg("Converting the User File to V3 ");
- dbg("This will take a while, I suggest you go and have cup of strong tea");
- my $odbm = tie (%oldu, 'DB_File', "$fn.v2", O_RDONLY, 0666, $DB_BTREE) or confess "can't open user file: $fn.v2 ($!) [rebuild it from user_asc?]";
- for ($action = R_FIRST; !$odbm->seq($key, $val, $action); $action = R_NEXT) {
- my $ref = asc_decode($val);
- if ($ref) {
- $ref->put;
- $count++;
- } else {
- $err++
- }
- }
- undef $odbm;
- untie %oldu;
- dbg("Conversion completed $count records $err errors");
+ if (-e $filename || $mode) {
+ $lru = LRU->newbase("DXUser", $lrusize);
+ if ($mode) {
+ $dbm = tie (%u, 'DB_File', $filename, O_CREAT|O_RDWR, 0666, $DB_BTREE) or confess "can't open user file: $fn ($!) [rebuild it from user_json?]";
+ } else {
+ $dbm = tie (%u, 'DB_File', $filename, O_RDONLY, 0666, $DB_BTREE) or confess "can't open user file: $fn ($!) [rebuild it from user_json?]";
+ }