Temporary file cleanup needs some love (UnitTest included!)

drewish - November 5, 2008 - 22:00
Project:Drupal
Version:7.x-dev
Component:system.module
Category:bug report
Priority:critical
Assigned:drewish
Status:closed
Description

I was looking at system_cron() and noticed that the temporary file clean up code could use some loving.

I've updated it to use the DBTNG queries and removed DELETE that was basically a no-op because file_delete() removes the record. I changed the SELECT query to match the status as a bitmapped field I need to double check that this is the correct query. Tests are included but I haven't been able to run them due to some problems with SimpleTest on my machine.

AttachmentSize
system_cron.patch4.26 KB
Testbed results
system_cron.patchfailedFailed: Failed to install HEAD. a href=http://testing.drupal.org/pifr/file/1/system_cron.patchDetailed results/a

#1

drewish - November 5, 2008 - 23:02
Status:needs work» needs review

Got the tests working and was able to get the status matching working correctly.

AttachmentSize
file_330633.patch 12.2 KB
Testbed results
file_330633.patchfailedFailed: Failed to apply patch. Detailed results

#2

drewish - November 5, 2008 - 23:03
Title:Temporary file cleanup needs some love» Temporary file cleanup needs some love (UnitTest included!)

maybe that'll lure in some reviews ;)

#3

grendzy - November 6, 2008 - 03:23

This looks pretty solid. All the relevant tests pass. I did remove this line:
+file_put_contents('/Users/amorton/Sites/dh/sites/default/files/drupal.log', print_r($row,1), FILE_APPEND);

AttachmentSize
file_330633_1.patch.txt 11.81 KB

#4

drewish - November 8, 2008 - 04:59

good catch on that... also noticed that i'd accidentally rolled #329226: Store file_test.module's values in variables rather than globals in with it. so here's your patch minus #329226.

AttachmentSize
file_330633.patch 4.58 KB

#5

grendzy - November 9, 2008 - 20:38
Status:needs review» reviewed & tested by the community

Ah, much clearer now. The unit tests still look good.

#6

Anonymous (not verified) - November 13, 2008 - 12:30
Status:reviewed & tested by the community» needs work

The last submitted patch failed testing.

#7

grendzy - November 13, 2008 - 16:57
Status:needs work» reviewed & tested by the community

Weird, the bot tested the wrong patch. #4 is the latest.

#8

Anonymous (not verified) - November 13, 2008 - 17:00
Status:reviewed & tested by the community» needs work

The last submitted patch failed testing.

#9

drewish - November 16, 2008 - 17:43
Status:needs work» reviewed & tested by the community

here's a re-roll.

AttachmentSize
file_330633.patch 4.61 KB
Testbed results
file_330633.patchpassedPassed: 8025 passes, 0 fails, 0 exceptions Detailed results

#10

Dries - November 24, 2008 - 12:07
Status:reviewed & tested by the community» needs work

In the code comments, that's should be that is, not?

Do these binary operations work on PostgreSQL and SQLite?

#11

drewish - November 24, 2008 - 12:46
Status:needs work» needs review

It's a standard ANSI SQL operator so it should work. installed sqlite and started to run all the system test but sweet jesus is it slow so just ran the cron tests and everything looked good.

I thought "that's" was a valid contraction of "that is" but i'm not looking to hold the patch up over an English quiz ;)

AttachmentSize
file_330633.patch 4.58 KB
Testbed results
file_330633.patchpassedPassed: 8025 passes, 0 fails, 0 exceptions Detailed results

#12

System Message - November 25, 2008 - 13:30
Status:needs review» needs work

The last submitted patch failed testing.

#13

drewish - November 25, 2008 - 14:10

Patch is failing because it was accidentally applied as part of #314870: UNSTABLE-4 blocker: Add api.php for every core module.

#14

Damien Tournoud - November 25, 2008 - 15:24

Breaks badly on PostgreSQL, with message:

PDOException: SELECT fid FROM {files} WHERE status & :permanent != :permanent AND timestamp < :timestamp - Array ( [:permanent] => 1 [:timestamp] => 1227604875 ) SQLSTATE[42P18]: Indeterminate datatype: 7 ERROR: could not determine data type of parameter $2 in system_cron() (line 1511 of /var/www/drupal/revamp/modules/system/system.module).

Back to the drawing board :)

#15

jhedstrom - November 26, 2008 - 18:04
Priority:normal» critical

This PDOException is breaking the postgresql installer. After commenting out the query in system_cron, the install works fine.

I found a similar issue, that was resolved with some PDO config magic:

http://bugs.php.net/bug.php?id=36652

#16

jhedstrom - November 26, 2008 - 22:15

I traced this down to the fact that the timestamp column is of type int_unsigned, and along the way filed this issue: #339588: Column type of int_unsigned causing pdoexception.

#17

Dave Reid - December 15, 2008 - 01:15

Should the bitwise operator be removed? I didn't think that was standard, acceptable thing to do. Plus the following just look weird...
WHERE status & :permanent != :permanent AND timestamp < :timestamp', array(':permanent' => FILE_STATUS_PERMANENT, ...

#18

drewish - December 15, 2008 - 06:03

Dave Reid, i think the problem was the way we did data types on pgsql. as far as i can tell pgsql supports them when you've got the right data types: http://www.postgresql.org/docs/7.4/static/functions-math.html

#19

drewish - December 25, 2008 - 03:43

#341910: file_space_used() not checking properly checking bitmapped status value (adds unit tests) was running into the same situation. the patch on #339588: Column type of int_unsigned causing pdoexception gets this passing and i'd guess addresses #341910 as well.

#20

drewish - December 25, 2008 - 04:11
Status:needs work» postponed

postponing until #339588: Column type of int_unsigned causing pdoexception get committed.

#21

drewish - December 26, 2008 - 19:53
Status:postponed» needs review

#22

System Message - December 26, 2008 - 19:53
Status:needs review» needs work

The last submitted patch failed testing.

#23

drewish - December 26, 2008 - 19:57
Status:needs work» needs review

okay that's freaking annoying... at least re-test it before slamming the status back...

#24

Dries - December 28, 2008 - 19:12
Status:needs review» fixed

Committed to CVS HEAD. Thanks, drewish.

#25

Damien Tournoud - January 4, 2009 - 12:04

The issue was that it is invalid to use both times the same placeholder:

<?php
$result = db_query('SELECT fid FROM {files} WHERE status & :permanent != :permanent AND timestamp < :timestamp', array(':permanent' => FILE_STATUS_PERMANENT, ':timestamp' => REQUEST_TIME - DRUPAL_MAXIMUM_TEMP_FILE_AGE));
?>

Here you are trying to use ":permanent" two times. This will fail when using the C prepare statement on PostgreSQL, and even of some PHP/MySQL configurations as reported in #352956: PDOException on install.

Please review the fix there.

#26

System Message - January 18, 2009 - 12:10
Status:fixed» closed

Automatically closed -- issue fixed for two weeks with no activity.

 
 

Drupal is a registered trademark of Dries Buytaert.