Staring in 5.0.0 PHP's mkdir() adds an option to create directories recursively. I think we should do this by default so I'd be able to replace:

file_check_directory($d = file_directory_path() .'/foo', FILE_CREATE_DIRECTORY);
file_check_directory($d = file_directory_path() .'/foo/bar', FILE_CREATE_DIRECTORY);
file_check_directory($d = file_directory_path() .'/foo/bar/baz', FILE_CREATE_DIRECTORY);

with

file_check_directory($d = file_directory_path() .'/foo/bar/baz', FILE_CREATE_DIRECTORY);
CommentFileSizeAuthor
file_check_directory_recursive.patch1.12 KBdrewish
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

drewish’s picture

Issue tags: +D7FileAPIWishlist, +trivial

adding some tags

jmstacey’s picture

subscribing for notification on commit.

quicksketch’s picture

Status: Needs review » Reviewed & tested by the community

This makes perfect sense to me. If you're curious about the drupal_chmod() right below the changed line, it does seem a little redundant but it serves the purpose of notifying watchdog if permissions are denied while chmoding the directory.

It'll be great to remove some loops in FileField with this enhancement. Currently I'm doing something like this:

$full_path = '';
foreach (explode('/', $directory) as $path) {
  $full_path .= $path . '/';
  file_check_directory($full_path, FILE_CREATE_DIRECTORY);
}

In comparison this is a dream. Thanks PHP 5!

This patch makes appropriate changes to our tests and is ready to go.

webchick’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs documentation

Committed with the addition of a small comment from drewish in IRC, since i had to go off and look up what parameters mkdir started taking while I wasn't looking. :)

Thanks! Please document this in the upgrade guide so that other modules can get rid of similarly nasty code.

quicksketch’s picture

quicksketch’s picture

Issue tags: -Needs documentation

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.