If the files directory doesn't exist yet, a call to file_create_path() returns bad data.
- call file_create_path('myfile') when /files doesn't exist: get back 'myfile'
- call file_create_path('myfile') when /files DOES exist: get back 'files/myfile'
The flow is this:
- my module (module_builder) calls file_create_path('hooks')
- file_create_path calls file_check_location('hooks', 'files'), having got the value of 'files' from file_directory_path().
- file_check_location() finds that the location doesn't exist, as it gets back nothing from realpath('hooks').
- file_check_location() rebuilds $source
- $directory = realpath($directory); places an empty string in $directory because 'files' doesn't exist.
- the strpos check isn't carried out
- $source is returned.
- file_create_path ignores this returned value, and returns the unchanged file it was given in the first place.
I'm not sure what you SHOULD get back in if 'files' doesn't exist -- either the same thing as if it did, or NULL? It's possibly up to modules to check this first but it still seems incorrect to return the current value.
Comments
Comment #1
joachim commentedExploring a bit more: this bug actually causes modules such as image.module to create their folder at the top level, ie image.module creates a folder '/images', because it calls file_check_directory with what it got back here.
Comment #2
casey commentedfile_create_path() is removed from d7 and replaced by file_prepare_directory(). Does this problem still exist?
Comment #3
NROTC_Webmaster commentedIf this is still an issue please change the status back to active.