proc env013 { } {
source ./include.tcl
global util_path
puts "Env013: Test fileid_reset."
set testfile A.db
set dupfile B.db
set nentries 500
set filenames "A B C D E"
foreach lorder { 1234 4321 } {
puts "\tEnv013.a: Creating env."
env_cleanup $testdir
set env [berkdb_env -create -home $testdir -txn]
error_check_good dbenv [is_valid_env $env] TRUE
puts "\tEnv013.b: Creating database with lorder $lorder."
foreach filename $filenames {
set db [eval {berkdb_open \
-pagesize 8192 -env $env -auto_commit \
-btree -create -mode 0644 $testfile $filename} ]
error_check_good dbopen [is_valid_db $db] TRUE
set t [$env txn]
error_check_good txn [is_valid_txn $t $env] TRUE
for { set i 0 } { $i < $nentries } { incr i } {
set key KEY.$i
set data DATA.$i
error_check_good\
db_put [$db put -txn $t $key $data] 0
}
error_check_good txn_commit [$t commit] 0
error_check_good db_close [$db close] 0
}
puts "\tEnv013.c: Copy database."
file copy -force $testdir/$testfile $testdir/$dupfile
puts "\tEnv013.d: Resetting file id for copied database."
error_check_good fileid_reset [$env id_reset $dupfile] 0
set orig_id [getfileid $testdir/$testfile]
puts "\tEnv013.d: orig: $orig_id"
set new_id [getfileid $testdir/$dupfile]
puts "\tEnv013.d: new: $new_id"
error_check_bad id_changed $orig_id $new_id
puts "\tEnv013.e: Verify and open database copy."
error_check_good verify [verify_dir $testdir "\tEnv013.e: "] 0
set db [eval {berkdb_open} \
-env $env -auto_commit -btree -mode 0644 -rdonly $dupfile]
error_check_good dup_open [is_valid_db $db] TRUE
error_check_good db_close [$db close] 0
error_check_good env_close [$env close] 0
}
}
proc getfileid { db } {
global util_path
set ret [exec $util_path/db_dump -da $db]
set uidstart [string first "uid:" $ret]
set uidend [string first "\tminkey:" $ret]
set uid [string range $ret $uidstart $uidend]
set uid [string trimright $uid]
return $uid
}