Hello,

I have noticed that the coder upgrade (Drupal 6 to 7) translates FILE_STATUS_TEMPORARY into ~FILE_STATUS_PERMANENT
As the value of FILE_STATUS_PERMANENT is 1, the result of the operation is -2
The status column of file_managed is signed, so -2 will be stored.

I've been checking the different references in the drupal code to the file status:

  • The system_cron hook checks for status different than FILE_STATUS_PERMANENT in order to purge temp files
  • The file module and the file field checks for file->status == 0 to check if the file is temporary

So, the first point will work with "-2" status but the second point won't.
Seems that here there's something inconsistent.
I've searching some info about how to set the file status properly but I haven't found anything clear enough.

Also, the Converting 6.x to 7.x guide treats the file status as a flag
https://drupal.org/update/modules/6/7#file_set_status

$file->status |= FILE_STATUS_PERMANENT;
$file = file_save($file);

If this is true, it means that to check if the file status is permanent you should check

if($file->status & FILE_STATUS_PERMANENT) {
    // [...]
}

At this point, I'm quite confused about how to set a file status to temporary properly.
I'd really appreciate if someone could add some info to help.

Thanks.

Comments

savioret’s picture

Title: How to handle temporary file status properly » How to set temporary file status properly
klausi’s picture

Status: Active » Closed (won't fix)

Coder 7.x is frozen now and will not receive updates. Coder 8.x-2.x can be used to check code for any Drupal version, Coder 8.x-2.x also supports the phpcbf command to automatically fix conding standard errors. Please check if this issue is still relevant and reopen against that version if necessary.