ID:               27990
 Updated by:       [EMAIL PROTECTED]
 Reported By:      csaba at alum dot mit dot edu
-Status:           Feedback
+Status:           No Feedback
 Bug Type:         SQLite related
 Operating System: Win 2K
 PHP Version:      5.0.0RC1
 New Comment:

No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.




Previous Comments:
------------------------------------------------------------------------

[2004-04-14 10:08:49] [EMAIL PROTECTED]

Please try using this CVS snapshot:

  http://snaps.php.net/php5-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5-win32-latest.zip

I think this was fixed just recently.


------------------------------------------------------------------------

[2004-04-14 07:45:06] csaba at alum dot mit dot edu

Description:
------------
I want to get a list of all SQLite databases under my root directory so
I figured I'd get a list of all the files, open each one using
sqlite_open, and assume those that didn't result in warnings/errors
were keepers.

sqlite_open is extremely unhappy about this and apache 2.0.48 dies.

Reproduce code:
---------------
$root = "c:\\Your\\Path\\Here";

$aFiles = dirList($root, 2, 1);
for ($i=sizeof($aFiles);$i--;) {
    if (!($db=sqlite_open($aFiles[$i],0666,$sqliteerror))) unset
($aFiles[$i]);
    else {
        if (!sqlite_array_query($db,"SELECT * FROM sqlite_master;",
SQLITE_ASSOC))
            unset ($aFiles[$i]);
        sqlite_close($db);
    }
}
var_dump ($aFiles);

function dirList($path=NULL, $types=2, $levels=1) {
//  returns an array of the specified files/directories
//  Note that directories are prefixed with a '*'
//      This can be eliminated from the line above the return
//  $path defaults to the current working directory
//  $types:  2 => files; 1 => directories; 3 => both;
//  $levels: 1 => look in the $path only; 2 => $path and all children;
//           3 => $path, children, grandchildren; 0 => $path and all
descendants;
//           less than 0 => complement of -$levels: everything starting
-$levels down
//                e.g. -1 => everthing except $path; -2 => all
descendants except $path + children

    $pathSep = strstr(PHP_OS, "WIN") ? "\\" : "/";
    if ([EMAIL PROTECTED]) $path = getcwd();
    $aRes = array();        // result
    $aAcc=array();          // accumulate
    $aDir = array(realpath($path));
    for
($i=$levels>0?$levels++:-1;$i--&&$aDir;$aDir=$aAcc,$aAcc=array())
        while ($dir = array_shift($aDir))
            foreach (scandir ($dir) as $fileOrDir)
                if ($fileOrDir!="." && $fileOrDir!="..") {
                    if ($isDir = is_dir ($rp="$dir$pathSep$fileOrDir"))
$aAcc[] = $rp;
                    if ($i<$levels-1 && ($types & (2-$isDir))) $aRes[]
= ($isDir?"*":"") . $rp; }
    return $aRes;
}


Expected result:
----------------
I expect to get a list of sqlite database files.  I expect to be able
to use @sqlite_open and have it fail gracefully (silently) without
taking PHP and Apache with it.


Actual result:
--------------
The above variant on my system with three files in the directory
(dbFile.db, index.php, index.php~) produced two warnings:

Warning: sqlite_open() [function.sqlite-open]: database disk image is
malformed in .../test.php on sqlite_open line
and showed the dbFile.db as OK

Every other variant crashes apache, such as doing a print of
$aFiles[$i] within the else, or inserting ' || $sqliteerror' as the
second half of the first if, or putting an '@' in front of
sqlite_open.

Thanks,
Csaba Gabor


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=27990&edit=1

Reply via email to