Don't delete existing downloads
This commit is contained in:
@@ -3,15 +3,30 @@
|
||||
|
||||
define("SITE_ROOT", realpath(dirname(__file__) . "/.."));
|
||||
require_once SITE_ROOT . "/lib/init.php";
|
||||
|
||||
function get_downloads()
|
||||
{
|
||||
global $DB;
|
||||
|
||||
$ret = array();
|
||||
|
||||
if (!$res = $DB->query("select file_name from downloads")) return;
|
||||
|
||||
while ($row = $DB->fetchRow($res)) {
|
||||
$ret[] = $row["file_name"];
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
$all_downloads = get_downloads();
|
||||
$sync = array("bz2", "log", "exe", "dmg");
|
||||
|
||||
$DB->query("begin");
|
||||
$DB->query("delete from downloads");
|
||||
|
||||
if ($dh = opendir(SITE_ROOT)) {
|
||||
while (($file = readdir($dh)) !== false) {
|
||||
$ext = pathinfo($file, PATHINFO_EXTENSION);
|
||||
if (in_array($ext, $sync)) {
|
||||
if (in_array($ext, $sync) && !in_array($file, $all_downloads)) {
|
||||
$q = kl_str_sql("insert into downloads(file_name) values (!s)", $file);
|
||||
$DB->query($q);
|
||||
}
|
||||
@@ -19,4 +34,4 @@ if ($dh = opendir(SITE_ROOT)) {
|
||||
closedir($dh);
|
||||
}
|
||||
|
||||
$DB->query("commit");
|
||||
|
||||
Reference in New Issue
Block a user