Summary: When running Drupal 7 on a Windows XP localhost webserver, many Simpletest tests raise file permission exceptions which do not occur when run under other operating systems. The affected tests (which include the SYSTEM: CRON RUN, REGISTRY PARSE FILES TEST, HTTP FILE RETRIEVAL and THEME INTERFACE FUNCTIONALITY tests), create temporary .htaccess files (within the sites/default/files/simpletest folder) with the read-only attribute set, which prevents their subsequent removal at the end of the tests. Furthermore, running the "Clean Environment" option from the testing page also fails to remove these files. The only way to remove them is to manually turn off the read-only file attribute bits (using Windows Explorer or other file management program), then re-run the "Clean Environment" test option.
As an example, here are the 6 exception messages which (repeatably) result from running the SYSTEM - HTTP FILE RETRIEVAL test from Drupal 7:
unlink(P:\htdocs\cms\drupal_head_cvs\sites\default\files\simpletest\129496\private\temp\.htaccess): Permission denied Warning file.inc 1006 file_unmanaged_delete() Exception
rmdir(P:\htdocs\cms\drupal_head_cvs\sites\default\files\simpletest\129496\private\temp): Directory not empty Warning file.inc 1053 file_unmanaged_delete_recursive() Exception
unlink(P:\htdocs\cms\drupal_head_cvs\sites\default\files\simpletest\129496\private\.htaccess): Permission denied Warning file.inc 1006 file_unmanaged_delete() Exception
rmdir(P:\htdocs\cms\drupal_head_cvs\sites\default\files\simpletest\129496\private): Directory not empty Warning file.inc 1053 file_unmanaged_delete_recursive() Exception
unlink(P:\htdocs\cms\drupal_head_cvs\sites\default\files\simpletest\129496\.htaccess): Permission denied Warning file.inc 1006 file_unmanaged_delete() Exception
rmdir(P:\htdocs\cms\drupal_head_cvs\sites\default\files\simpletest\129496): Directory not empty Warning file.inc 1053 file_unmanaged_delete_recursive() Exception
Discussion: The problem is due to the fact that temporary .htaccess files are created with file permissions set to 0444 (which under Unix-like OSs means: read, no write and no execute access for user, group and others). Drupal 7 testing code creates these files with a call to the file_create_htaccess() function in the includes/file.inc file. Under Windows (for both FAT32 and NTFS file systems), calling chmod('file', 0444) results in setting the read-only attribute bit for these newly created .htaccess files. Once Simpletest is finished with these temporary files, it calls the file_unmanaged_delete function (also within: includes/file.inc). This function calls the PHP unlink function to delete the file, but this fails under Windows because the file has the read-only attribute bit set. Note that the unlink function works under Unix-like OSs, because the permissions of the containing directory, and not the file itself, determines if a file can be removed or not.
Steps required to reproduce the bug:
- Install Drupal-7 on a Windows test platform. Select all default options.
- Enable the testing module.
- Run the SYSTEM - HTTP FILE RETRIEVAL test. (6 exceptions will occur and 3 temporary
.htaccessfiles with read-only attributes are left in thesites/default/files/simpletestbranch.) - Attempt to remove these files by clicking the "Clean Environment" button on the testing page. (6 warnings occur and the temporary files are not removed.)
- Repeat the previous step. (The same 6 warnings occur every time this is attempted.)
- Using Windows Explorer, manually turn off the read-only attributes for each of the 3
.htaccessfiles. (Right click each file, select "properties", un-check the "read-only" checkbox and click OK). - Once again click the "Clean Environment" button. (This time the 3 temporary files and their folders are successfully removed.)
The Fix: When creating each of these temporary files, do not set the read-only attribute bit under Windows. This is accomplished simply by changing the file creation mode from 0444 to 0644 (which gives the owner of the file write access). This requires changing only one byte of one file. In the file_create_htaccess function in includes/file.inc, change this line:
drupal_chmod($htaccess_path, 0444);
to this:
drupal_chmod($htaccess_path, 0644);
Once this change is made, these exceptions never occur. See attached patch for fix.
(Note that my localhost webserver is running Windows XP SP2 with Apache-2.2.11 and PHP-5.2.9-2. My guess is that this same problem will occur under Windows 2000, Windows Vista and Windows 7 as well.)
| Comment | File | Size | Author |
|---|---|---|---|
| rr_0444_bugfix_20100325.patch | 668 bytes | ridgerunner |
Comments
Comment #1
ridgerunner commentedChanged status to (hopefully) trigger test bot.
Comment #2
mr.baileysDuplicate of #443286: Windows File Handling: International characters break file handling, permissions don't translate. Would you mind reviewing the patch there (or add your patch to that issue if you feel the existing patch does not properly address the bug)?
Comment #3
ridgerunner commentedYes I can confirm that the patch provided in post #18 of the "file tests failing on Windows" issue, does indeed address and fix the problem I outlined above in this issue.
I concur that this issue is a duplicate and all further discussion on this issue will be made over there.
Note, however, that the comments provided above do provide additional details on how and why these exceptions occur.
Comment #6
mr.baileys