Duplicated code in Load.php

Started by ZerK, July 11, 2014, 02:36:07 AM

Previous topic - Next topic

ZerK

starting at line 2633:


if (function_exists('file_put_contents'))
{
$cache_bytes = @file_put_contents($cachedir . '/data_' . $key . '.php', $cache_data, LOCK_EX);
if ($cache_bytes != strlen($cache_data))
@unlink($cachedir . '/data_' . $key . '.php');
}
else
{
// Write the file.
if (function_exists('file_put_contents'))
{
$cache_bytes = @file_put_contents($cachedir . '/data_' . $key . '.php', $cache_data, LOCK_EX);
if ($cache_bytes != strlen($cache_data))
@unlink($cachedir . '/data_' . $key . '.php');
}
else
{
$fh = @fopen($cachedir . '/data_' . $key . '.php', 'w');
if ($fh)
{
// Write the file.
set_file_buffer($fh, 0);
flock($fh, LOCK_EX);
$cache_bytes = fwrite($fh, $cache_data);
flock($fh, LOCK_UN);
fclose($fh);

// Check that the cache write was successful; all the data should be written
// If it fails due to low diskspace, remove the cache file
if ($cache_bytes != strlen($cache_data))
@unlink($cachedir . '/data_' . $key . '.php');
}
}
}


If the first condition doesnt meet, then the first if after the else wont either, im using smf 2.0.8 also downloaded it again to check if it was like that and it is.

PD: also checked 2.1 github but its fixed there.

Oldiesmann

Thanks for the report. Since this isn't causing any problems, it won't be fixed for 2.0. The extra processing power required to check whether the function exists a second time is minimal, and in most cases we won't even hit "else" part now (since file_put_contents was added in PHP5 - I doubt there are many servers running anything older than that at this point).
Michael Eshom
Christian Metal Fans

Arantor

That was originally changed in 2.0.7 but that's not the stock 2.0.7 code.

It's almost like you'd already changed the code previously and then 2.0.7 changed it again.

live627

SMF is infested with duplicate code.

Arantor

Sure it is. This code, however, is artificially duplicate and is not present in a stock 2.0.7 or 2.0.8 install as far as I can tell.

ZerK

weird because i downloaded the latest version when i checked  it and it was like that. maybe its only duplicated in one of the mirrors ?

Arantor

This is fantastic. I'm trying to understand exactly what happened.

2.0.7 contains the rewrite of that part of the code. 2.0.8 makes no changes.

A 2.0.7 clean download that I have has the code as I wrote it.
A 2.0.8 clean download has this strange code, which is not as I wrote in 2.0.7 or 2.0.8's patch files, which suggests something funky about the patches as applied to the core code prior to release.

Awesome.

Advertisement: