diff -u b/core/includes/file.inc b/core/includes/file.inc --- b/core/includes/file.inc +++ b/core/includes/file.inc @@ -524,7 +524,7 @@ else { // Perhaps $destination is a dir/file? $dirname = drupal_dirname($destination); - if (!file_prepare_directory($dirname)) { + if (!file_prepare_directory($dirname, FILE_CREATE_DIRECTORY)) { // The destination is not valid. $logger->notice('File %file could not be moved/copied because the destination directory %destination is not configured correctly.', array('%file' => $original_source, '%destination' => $dirname)); drupal_set_message(t('The specified file %file could not be moved/copied because the destination directory is not properly configured. This may be caused by a problem with file or directory permissions. More information is available in the system log.', array('%file' => $original_source)), 'error'); @@ -574,7 +574,7 @@ else { // Perhaps $destination is a dir/file? $dirname = drupal_dirname($destination); - if (!file_prepare_directory($dirname, FILE_CREATE_DIRECTORY)) { + if (!file_prepare_directory($dirname)) { // The destination is not valid. $logger->notice('File %file could not be copied because the destination directory %destination is not configured correctly.', array('%file' => $original_source, '%destination' => $dirname)); drupal_set_message(t('The specified file %file could not be copied because the destination directory is not properly configured. This may be caused by a problem with file or directory permissions. More information is available in the system log.', array('%file' => $original_source)), 'error'); only in patch2: unchanged: --- a/core/tests/Drupal/KernelTests/Core/File/UnmanagedCopyTest.php +++ b/core/tests/Drupal/KernelTests/Core/File/UnmanagedCopyTest.php @@ -84,6 +84,14 @@ function testOverwriteSelf() { $this->assertTrue(file_exists($uri), 'Original file exists after copying onto itself.'); $this->assertTrue(file_exists($new_filepath), 'Copied file exists after copying onto itself.'); $this->assertFilePermissions($new_filepath, Settings::get('file_chmod_file', FileSystem::CHMOD_FILE)); + + // Copy the file into a subdirectory that does not exist. + $new_filepath = file_unmanaged_copy($uri, drupal_dirname($uri) . '/sub/' . drupal_basename($uri), FILE_EXISTS_ERROR); + $this->assertTrue($new_filepath, 'Copying into same directory works.'); + $this->assertNotEqual($new_filepath, $uri, 'Copied file has a new name.'); + $this->assertTrue(file_exists($uri), 'Original file exists after copying onto itself.'); + $this->assertTrue(file_exists($new_filepath), 'Copied file exists after copying onto itself.'); + $this->assertFilePermissions($new_filepath, Settings::get('file_chmod_file', FileSystem::CHMOD_FILE)); } } only in patch2: unchanged: --- a/core/tests/Drupal/KernelTests/Core/File/UnmanagedMoveTest.php +++ b/core/tests/Drupal/KernelTests/Core/File/UnmanagedMoveTest.php @@ -38,6 +38,15 @@ function testNormal() { $this->assertFalse(file_exists($new_filepath), 'No file remains at the old location.'); $this->assertFilePermissions($newer_filepath, Settings::get('file_chmod_file', FileSystem::CHMOD_FILE)); + // Moving the file into a subdirectory that does not exist. + $desired_filepath = 'public://sub/' . $this->randomMachineName(); + $newest_filepath= file_unmanaged_move($newer_filepath, $desired_filepath, FILE_EXISTS_ERROR); + $this->assertTrue($newest_filepath, 'Move was successful.'); + $this->assertEqual($newest_filepath, $desired_filepath, 'Returned expected filepath.'); + $this->assertTrue(file_exists($newest_filepath), 'File exists at the new location.'); + $this->assertFalse(file_exists($newer_filepath), 'No file remains at the old location.'); + $this->assertFilePermissions($newest_filepath, Settings::get('file_chmod_file', FileSystem::CHMOD_FILE)); + // TODO: test moving to a directory (rather than full directory/file path) // TODO: test creating and moving normal files (rather than streams) }