Browse Source

solved bug on setDB found by Sebastien Lion (recompilation trigger)

hg/35a367e65a464cf6cdf277c73f977a6828b723fe/bookmarks/master
Martin Monperrus 14 years ago
parent
commit
9a335a202b
  1. 13
      bibtexbrowser.php
  2. 43
      test/04_setDB.php
  3. 7
      test/output/04_setDB.txt

13
bibtexbrowser.php

@ -391,7 +391,7 @@ function setDB() {
// we try to save a "compiled" in a txt file
$compiledbib = 'bibtexbrowser_'.md5($_GET[Q_FILE]).'.dat';
$parse=true;
$parse=false;
foreach(explode(MULTIPLE_BIB_SEPARATOR, $_GET[Q_FILE]) as $bib) {
// do we have a compiled version ?
if (is_file($compiledbib) && is_readable($compiledbib)) {
@ -401,12 +401,11 @@ function setDB() {
$_GET[Q_DB] = unserialize(file_get_contents($compiledbib));
// basic test
// do we have an correct version of the file
if (is_a($_GET[Q_DB],'BibDataBase')) {
// at least we can switch off the parsing
$parse=false;
if (!is_a($_GET[Q_DB],'BibDataBase')) {
$parse=true;
}
}
}
} else {$parse=true;}
} else {$parse=true;}
} // end for each
// we don't have a compiled version
@ -431,6 +430,8 @@ function setDB() {
}
//else echo '<!-- please chmod the directory containing the bibtex file to be able to keep a compiled version (much faster requests for large bibtex files) -->';
} // end parsing and saving
return $parse;
} // end function setDB

43
test/04_setDB.php

@ -0,0 +1,43 @@
<?
// testing the recompilation
// bug found by Sébastien Lion
$_GET['test']=1;
include(dirname(__FILE__).'/../bibtexbrowser.php');
$a = tempnam('/tmp','').".bib";
$b = tempnam('/tmp','').".bib";
file_put_contents($a, "@misc{f,title=foo}");
file_put_contents($b, "@misc{g,title=bar}");
sleep(2);
$_GET['bib']=$a.";".$b;
function boolString($bValue = false) { // returns string
return ($bValue ? 'true' : 'false');
}
$result = '';
$result .= 'should be true:'.boolString(setDB())."\n";
$result .= 'should be false:'.boolString(setDB())."\n";
$result .= 'should be false:'.boolString(setDB())."\n";
touch($a);
sleep(2);
$result .= 'should be true:'.boolString(setDB())."\n";
$result .= 'should be false:'.boolString(setDB())."\n";
touch($b);
sleep(2);
$result .= 'should be true:'.boolString(setDB())."\n";
$result .= 'should be false:'.boolString(setDB())."\n";
echo $result;
file_put_contents('output/04_setDB.txt',$result);
// clean
unlink($a);
unlink($b);
?>

7
test/output/04_setDB.txt

@ -0,0 +1,7 @@
should be true:true
should be false:false
should be false:false
should be true:true
should be false:false
should be true:true
should be false:false
Loading…
Cancel
Save