Enabling an upload on for example an image node will break things: if the user uploads a file called "_original" attached to a image node, there will be two rows in the files table:

mysql> select * from files;
+-----+-----+-----------+-----------------------------+--------------------------+----------+------+
| fid | nid | filename  | filepath                    | filemime                 | filesize | list |
+-----+-----+-----------+-----------------------------+--------------------------+----------+------+
|   3 |   2 | _original | images/01_0.jpg             | image/jpeg               |   152053 |    0 |
|   4 |   2 | thumbnail | images/01_0.thumbnail-0.jpg | image/jpeg               |     2278 |    0 |
|   5 |   2 | _original | files/_original             | application/octet-stream |        0 |    1 |
+-----+-----+-----------+-----------------------------+--------------------------+----------+------+

The problem with this is that image module doesn't know anymore what file to use as its "_original" image. If it happens to use the wrong one, viewing a image node will fail (as the _original file someone uploads doesn't need to be a image file).

If a module wants to use the files table (what is suggested I think), then a module needs to have a way of saying: "what are the rows in the files table I have created? I (and I alone) know how to deal with them".

There are some solutions for this:

  • all modules that use the files table use a filename as "-". Ugly!
  • do a SELECT * FROM {files} WHERE filemime LIKE 'image/%'. This works for image module (probably) but is not general.
  • Add a "module" column (or "owner" I'm not sure of the convention in other tables).

This way a module can figure out what files it should handle and what files to leave alone.

What do you think?

Comments

eafarris’s picture

Wouldn't this be solved by http://drupal.org/node/28769, where each node or user has their own directory? IMO, the files space should be organized by nid. Using filename alone, as you describe, isn't enough.

Robrecht Jacques’s picture

No, it wouldn't be solved by a saner directory structure (although that is a nice feature too). What I'm talking about is the problem that two modules can't really be sure which one of the two added the file to the files table.
Currently there seems to be made only a distinction between "upload module added the file (list = 1)" and "another module added the file (list = 0)". IMO that is not enough: I know now that I can distinguish by looking at the "list" column, but if another module uses the files table to attach a file to a node, this will have list = 0 too.

With a "module" column added I could do SELECT * FROM {files} WHERE nid = %d AND module = 'mymodule' and I would only get the files I, as a module developer, am interested in.

Zen’s picture

Priority: Critical » Normal

This to me, is something of an extreme scenario, that can be classified either as a normal/minor bug or a critical feature request. Also, though I've not used the image module myself, from your example, a temporary workaround could be to base the SELECT on the filepath as well - i.e. use the directory structure to differentiate..

Reclassifying as normal.
-K

moshe weitzman’s picture

yup, this is a significant bug in our upload system. bitten me a few times.

moshe weitzman’s picture

Status: Active » Closed (duplicate)

found my older report of this issue: http://drupal.org/node/33482