Welcome Guest, Not a member yet? Register   Sign In
index.php, system_folder variable and multisite installation on windows
#9

[eluser]xadio[/eluser]
Quote:xadio, I merged your report with this existing thread from a few days ago. Please see the comments above.

Thanks Derek, I didn't take a lot of effort to search if this existed so my apologies to the forum members.

Although slight as it is, I should probably use '/' instead of '\\' because it is replaced either way. However, the str_replace function exists so I would assume this was an intended possibility. If not then it should be reflected in the code and the User Guide.

I still stand by my point that this is a bug. The definition of the conditional does not work for what appear to be intended.
Code:
if(TRUE){} // This is just to correct the php highlight problem

// Note: If needle is not found, strpos() will return boolean FALSE.
//       So a string such as "C:\www\codeigniter\system" will return the
//       boolean FALSE making the conditional TRUE.
if (strpos($system_folder, '/') === FALSE) {...}
//       So when does the following execute?  When a $system_folder equals
//       "/www/codeigniter/system".  Then this function is useless for its
//       intended purpose. The other situation seems unlikely though. When would
//       someone do one of the following?
//       "C:/www\codeigniter\system"
//       "C:\www/codeigniter\system"
//       This means the following code is unnecessary unless these are used:
//       "/www\codeigniter/www"
//       "\www/codeigniter/www"
else
{
  $system_folder = str_replace('\\', '/', $system_folder);
}

I should wait to post this later as I am on a *nix box right now and cannot test the following on a win machine, but I won't wait. Wink Please take it with/as a grain of salt.

Code:
if(TRUE){} // This is just to correct the php highlight problem

// This is a few more lines of code, but I believe this adequately does what was intentionally desired
//  for both *nix and windows. Please note that on BSD systems realpath() doesn't fail if only the last path
//  component doesn't exist, while other systems will return FALSE.

// Function 'realpath' exists then handle *nix and win absolute paths
if (function_exists('realpath') &&
    (DIRECTORY_SEPARATOR == '/'  && strpos($system_folder, '/') !== 0) ||
    (DIRECTORY_SEPARATOR == '\\' && strpos($system_folder, ':') !== 1)) { //Not sure if Windows allows dirs with :

  // Extract path __FILE__ then create a realpath of `pwd`/$system_folder
  if (($dirpath = realpath(dirname(__FILE__)) . '/') !== FALSE && ($realpath = realpath($dirpath . '/' . $system_folder)) !== FALSE) {
    $system_folder = $realpath;
  }
  else if (isset($dirpath)) {
    die("\$system_folder [$system_folder] does not exist in \"$dirpath\".");
  }
}

// Swap directory separators to Unix style for consistency
$system_folder = str_replace("\\", "/", $system_folder);

//Double check that file exists; especially for BSD
if (!file_exists($system_folder)) {
  die("\$system_folder [$system_folder] does not exist.");
}

//Clear cache just incase
clearstatcache();

Benchmarks (seconds):
Code:
Test: /tmp/absolute_exists
----
Old: 6.2E-5
New: 4.5E-5

Test: relative_exists
----
Old: 4.1E-5
New: 3.6E-5

Test: /absolute_notexists
----
Old: 7.99999999998E-6
New: 1.3E-5

Test: relative_notexists
----
Old: 1.9E-5
New: 2.3E-5

The benchmarks above are the worst case scenario I could come up with after running it numerous times.

So there is slight decrease in time for working cases while an increase in functionality, ignoring failed cases as it doesn't impact the speed of the overall system. Please note that I have not tested this in Windows, but I will try and report back later.

If you want the php with benchmarks to test yourself just let me know.

Please critique if you see an error in my logic/code.


Messages In This Thread
index.php, system_folder variable and multisite installation on windows - by El Forum - 01-29-2008, 01:54 AM



Theme © iAndrew 2016 - Forum software by © MyBB