When trying to setup automated resets, kept receiving an error "The snapshot directory demo could not be created."

Did some digging and the offender was the call to file_prepare_directory in demo_admin_settings_validate [demo.admin.inc]. As the "private://" stream identifier was not passed, the file_prepare_directory function would fail as there would be no directory to find. Adding in the stream identifier so there was a full URI to parse fixed the issue.

Before Fix

function demo_admin_settings_validate($form, &$form_state) {
  if (!file_prepare_directory($form_state['values']['demo_dump_path'], FILE_CREATE_DIRECTORY)) {
    form_set_error('demo_dump_path', t('The snapshot directory %directory could not be created.', array('%directory' => $form_state['values']['demo_dump_path'])));
  }
}

After Fix

function demo_admin_settings_validate($form, &$form_state) {
 $fullpath = 'private://'.$form_state['values']['demo_dump_path'];
 $dirprep = file_prepare_directory($fullpath, FILE_CREATE_DIRECTORY);
 if (!$dirprep) {
   form_set_error('demo_dump_path', t('The snapshot directory %directory could not be created.', array('%directory' => $form_state['values']['demo_dump_path'])));
  }
}
CommentFileSizeAuthor
#2 addprivateprefix-1153206-2.patch859 bytesZeiP
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

BarisW’s picture

Version: 7.x-1.0 » 7.x-1.x-dev

I can confirm this. It only goes wrong when the default file system settings are set to public. I changed the code to this:

function demo_admin_settings_validate($form, &$form_state) {
  $directory = 'private://' . $form_state['values']['demo_dump_path'];
  if (!file_prepare_directory($directory, FILE_CREATE_DIRECTORY)) {
    form_set_error('demo_dump_path', t('The snapshot directory %directory could not be created.', array('%directory' => $form_state['values']['demo_dump_path'])));
  }
}
ZeiP’s picture

Status: Active » Needs review
FileSize
859 bytes

I had the same problem, the change in #1 worked. Attached is a patch to fix this.

davidtrainer’s picture

Status: Needs review » Reviewed & tested by the community

I can confirm this patch works.

izmeez’s picture

Component: Demo Reset » Code
Issue summary: View changes

I can also confirm this patch applies to 7.x-1.x-dev and works. It resolves #2072229: Demo settings should return ok message if path already exists that i shall close as a duplicate of this issue.

Thanks.

cecrs’s picture

Also can confirm the patch works.

gaurav.kapoor’s picture

Lil documentation would improve the patch. Will add that while commit.

gaurav.kapoor’s picture

Status: Reviewed & tested by the community » Fixed
gaurav.kapoor’s picture

Status: Fixed » Closed (fixed)

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