In "mod/resource/db/upgrade.php" at line 180, conversion for versions older than 2009062603 calls "resource_20_migrate()". This sets a filed in "resource" table called "mainfile". That part works correctly. Later at line 219 the conversion code for versions older than 2009080501 removed the "mainfile" field from the "resource" table, and instead sets a field called "sortorder". At line 235 the PHP function "dirname" is used, which on Windows systems may return Windows style directory separators '
'. Since the "files" library doesn't follow the Windows conventions, this leads to problems. Specifically, the line
$filepath = file_correct_filepath(dirname($instance->mainfile));
often returns '/
/'. Two lines later, function "file_set_sortorder()" is called, but fails because the $filepath condition is not met. No error message is produced at this point.
After the conversion completes, links to resource files will be unreliable. This is because each file actually has 2 entries in the file table. One for the file itself and one for a related file with name "." (the containing directory?). Since the sortorder never gets set, the "view" code picks whichever one comes back first from the query. Sometimes it works and sometimes it results in a "File Not Found" error. If sortorder had been set correctly, the view code would work correctly.
I made a temporary fix with the lines:
if( $filepath == '/
BTW, the "sortorder" field is not mentioned in "http://docs.moodle.org/en/Development:Using_the_file_API". It would be helpful if somebody could explain its use. I see how it's is being used for resource files, but am unclear about the more general case.