? .DS_Store
? .buildpath
? .cache
? .git
? .project
? .settings
? 352956-the-tale-of-two-placeholders_0.patch
? empty
? file_341910_0.patch
? logs
? test.php
? profiles/default/translations
? sites/.DS_Store
? sites/all/.DS_Store
? sites/all/modules
? sites/default/.DS_Store
? sites/default/files
? sites/default/settings.php
Index: includes/file.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/file.inc,v
retrieving revision 1.149
diff -u -p -r1.149 file.inc
--- includes/file.inc	2 Jan 2009 21:45:11 -0000	1.149
+++ includes/file.inc	5 Jan 2009 02:08:19 -0000
@@ -767,10 +767,12 @@ function file_unmanaged_delete($path) {
  *   An integer containing the number of bytes used.
  */
 function file_space_used($uid = NULL, $status = FILE_STATUS_PERMANENT) {
+  // Use separate placeholders for the status to avoid a bug in some versions
+  // of PHP. @see http://drupal.org/node/352956
   if (!is_null($uid)) {
-    return db_query('SELECT SUM(filesize) FROM {files} WHERE uid = :uid AND status = :status', array(':uid' => $uid, ':status' => $status))->fetchField();
+    return db_query('SELECT SUM(filesize) FROM {files} WHERE uid = :uid AND status & :status1 = :status2', array(':uid' => $uid, ':status1' => $status, ':status2' => $status))->fetchField();
   }
-  return db_query('SELECT SUM(filesize) FROM {files} WHERE status = :status', array(':status' => $status))->fetchField();
+  return db_query('SELECT SUM(filesize) FROM {files} WHERE status & :status1 = :status2', array(':status1' => $status, ':status2' => $status))->fetchField();
 }
 
 /**
Index: modules/simpletest/tests/file.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/tests/file.test,v
retrieving revision 1.17
diff -u -p -r1.17 file.test
--- modules/simpletest/tests/file.test	2 Jan 2009 21:45:11 -0000	1.17
+++ modules/simpletest/tests/file.test	5 Jan 2009 02:08:19 -0000
@@ -130,6 +130,67 @@ class FileHookTestCase extends FileTestC
   }
 }
 
+
+/**
+ *  This will run tests against the file_space_used() function.
+ */
+class FileSpaceUsedTest extends FileTestCase {
+  function getInfo() {
+    return array(
+      'name' => t('File space used tests'),
+      'description' => t('Tests the file_space_used() function.'),
+      'group' => t('File'),
+    );
+  }
+
+  function setUp() {
+    parent::setUp();
+
+    // Create records for a couple of users with different sizes.
+    drupal_write_record('files', $file = array('uid' => 2, 'filesize' => 50, 'status' => FILE_STATUS_PERMANENT));
+    drupal_write_record('files', $file = array('uid' => 2, 'filesize' => 20, 'status' => FILE_STATUS_PERMANENT));
+    drupal_write_record('files', $file = array('uid' => 3, 'filesize' => 100, 'status' => FILE_STATUS_PERMANENT));
+    drupal_write_record('files', $file = array('uid' => 3, 'filesize' => 200, 'status' => FILE_STATUS_PERMANENT));
+
+    // Now create some with other statuses. These values were chosen arbitrarily
+    // for the sole purpose of testing that bitwise operators were used
+    // correctly on the field.
+    drupal_write_record('files', $file = array('uid' => 2, 'filesize' => 1, 'status' => 2 | 8));
+    drupal_write_record('files', $file = array('uid' => 3, 'filesize' => 3, 'status' => 2 | 4));
+  }
+
+  /**
+   * Test different users with the default status.
+   */
+  function testUser() {
+    $this->assertEqual(file_space_used(2), 70, t("Found the size of the first user's files."));
+    $this->assertEqual(file_space_used(3), 300, t("Found the size of the second user's files."));
+    $this->assertEqual(file_space_used(), 370, t("Found the size of all user's files."));
+  }
+
+  /**
+   * Test the status fields
+   */
+  function testStatus() {
+    // Check selection with a single bit set.
+    $this->assertEqual(file_space_used(NULL, 2), 4, t("Found the size of all user's files with status 2."));
+    $this->assertEqual(file_space_used(NULL, 4), 3, t("Found the size of all user's files with status 4."));
+    // Check that the bitwise AND operator is used when selecting so that we
+    // only get files with the 2 AND 4 bits set.
+    $this->assertEqual(file_space_used(NULL, 2 | 4), 3, t("Found the size of all user's files with status 6."));
+  }
+
+  /**
+   * Test both the user and status.
+   */
+  function testUserAndStatus() {
+    $this->assertEqual(file_space_used(1, 8), 0, t("Found the size of the admin user's files with status 8."));
+    $this->assertEqual(file_space_used(2, 8), 0, t("Found the size of the first user's files with status 8.". file_space_used(2, 8)));
+    $this->assertEqual(file_space_used(2, 2), 0, t("Found the size of the first user's files with status 2."), file_space_used(2, 2));
+    $this->assertEqual(file_space_used(3, 2), 3, t("Found the size of the second user's files with status 2."), file_space_used(3, 2));
+  }
+}
+
 /**
  *  This will run tests against the file validation functions (file_validate_*).
  */
