[geeklog-cvs] geeklog: Some ugly workarounds to cope with files > 2GB on some ...
geeklog-cvs at lists.geeklog.net
geeklog-cvs at lists.geeklog.net
Sat Jan 29 11:43:00 EST 2011
changeset 8084:e45bf0daff6f
url: http://project.geeklog.net/cgi-bin/hgwebdir.cgi/geeklog/rev/e45bf0daff6f
user: Dirk Haun <dirk at haun-online.de>
date: Sat Jan 29 17:10:14 2011 +0100
description:
Some ugly workarounds to cope with files > 2GB on some 32 bit systems (bug #0001257)
diffstat:
public_html/admin/database.php | 53 ++++++++++++++++++++++++++++++++++++++---
1 files changed, 48 insertions(+), 5 deletions(-)
diffs (89 lines):
diff -r e7269564603f -r e45bf0daff6f public_html/admin/database.php
--- a/public_html/admin/database.php Sat Jan 29 14:18:20 2011 +0100
+++ b/public_html/admin/database.php Sat Jan 29 17:10:14 2011 +0100
@@ -2,13 +2,13 @@
/* Reminder: always indent with 4 spaces (no tabs). */
// +---------------------------------------------------------------------------+
-// | Geeklog 1.6 |
+// | Geeklog 1.8 |
// +---------------------------------------------------------------------------+
// | database.php |
// | |
// | Geeklog database backup and maintenance page. |
// +---------------------------------------------------------------------------+
-// | Copyright (C) 2000-2009 by the following authors: |
+// | Copyright (C) 2000-2011 by the following authors: |
// | |
// | Authors: Tony Bibbs - tony AT tonybibbs DOT com |
// | Blaine Lang - langmail AT sympatico DOT ca |
@@ -72,8 +72,15 @@
{
global $_CONF;
- $lFiletimeA = filemtime($_CONF['backup_path'] . $pFileA);
- $lFiletimeB = filemtime($_CONF['backup_path'] . $pFileB);
+ $lFiletimeA = @filemtime($_CONF['backup_path'] . $pFileA);
+ $lFiletimeB = @filemtime($_CONF['backup_path'] . $pFileB);
+
+ // filemtime() may fail on 32 bit system when the file is > 2GB.
+ // Sort alphabetically instead, assuming there's a date in the file name.
+ if (($lFiletimeA === false) || ($lFiletimeB === false)) {
+ return strcmp($pFileA, $pFileB);
+ }
+
if ($lFiletimeA == $lFiletimeB) {
return 0;
}
@@ -82,6 +89,42 @@
}
/**
+* Helper function to get a file's size
+*
+* The PHP filesize() method may fail on 32 bit systems with files > 2 GB
+* or may return negative values (Windows only?). So this function tries some
+* workarounds, but may eventually just give up and return zero ...
+*
+* @param string $filename full path of the file
+* @return mixed int or float value: size of the file
+*
+*/
+function filesizeHelper($filename)
+{
+ $size = @filesize($filename);
+
+ if (($size === false) || ($size < 0)) {
+ // filesize() may fail on 32 bit systems with files > 2GB
+ // - try some workarounds
+ $size = 0;
+ if (PHP_OS == 'Linux') {
+ $option = '-c %s';
+ } elseif ((strpos(PHP_OS, 'BSD') !== false) || (PHP_OS == 'Darwin')) {
+ // Wouldn't it be nice if all *NIX commands had the same options?
+ $option = '-f %z';
+ }
+ if (! empty($option)) {
+ $size = (float) exec("stat $option " . escapeshellarg($filename));
+ if ($size <= 0) {
+ $size = 0;
+ }
+ }
+ }
+
+ return $size;
+}
+
+/**
* List all backups, i.e. all files ending in .sql
*
* @return string HTML for the list of files or an error when not writable
@@ -122,7 +165,7 @@
$downloadLink = COM_createLink($backups[$i], $downloadUrl,
array('title' => $LANG_DB_BACKUP['download']));
$backupfile = $_CONF['backup_path'] . $backups[$i];
- $backupfilesize = COM_numberFormat(filesize($backupfile))
+ $backupfilesize = COM_numberFormat(filesizeHelper($backupfile))
. ' <b>' . $LANG_DB_BACKUP['bytes'] . '</b>';
$data_arr[$i] = array('file' => $downloadLink,
'size' => $backupfilesize,
More information about the geeklog-cvs
mailing list