When a file copy fails, the error message that is logged is very limited in that it doesn't give the destination path that is causing the issue.
File: core/lib/Drupal/Core/File/FileSystem.php
Current version
// Perhaps $destination is a dir/file?
$dirname = $this->dirname($destination);
if (!$this->prepareDirectory($dirname)) {
$this->logger->error("The specified file '%original_source' could not be copied because the destination directory is not properly configured. This may be caused by a problem with file or directory permissions.", [
'%original_source' => $original_source
]);
throw new DirectoryNotReadyException("The specified file '$original_source' could not be copied because the destination directory is not properly configured. This may be caused by a problem with file or directory permissions.");
}
Example log output: The specified file 'temporary://filehDDLEO' could not be copied because the destination directory is not properly configured. This may be caused by a problem with file or directory permissions.
Proposed change
// Perhaps $destination is a dir/file?
$dirname = $this->dirname($destination);
if (!$this->prepareDirectory($dirname)) {
$this->logger->error("The specified file '%original_source' could not be copied because the destination directory '%destination_dir' is not properly configured. This may be caused by a problem with file or directory permissions.", [
'%original_source' => $original_source,
'%destination_dir' => $dirname
]);
throw new DirectoryNotReadyException("The specified file '$original_source' could not be copied because the destination directory '$dirname' is not properly configured. This may be caused by a problem with file or directory permissions.");
}
Example log output: The specified file 'temporary://filehDDLEO' could not be copied because the destination directory 'public://aaa/bbb' is not properly configured. This may be caused by a problem with file or directory permissions.
Comment | File | Size | Author |
---|---|---|---|
#19 | interdiff-3070902-12-19.txt | 1.1 KB | mrinalini9 |
#19 | better-logging-for-preparedestination-exception-3070902-19.patch | 2.68 KB | mrinalini9 |
#12 | interdiff-3070902-7-12.txt | 1.44 KB | mrinalini9 |
Comments
Comment #2
mrupsidown CreditAttribution: mrupsidown commentedComment #3
mrupsidown CreditAttribution: mrupsidown commentedComment #4
digitaldonkey CreditAttribution: digitaldonkey commentedPlease https://www.drupal.org/project/drupal/issues/3070902
Comment #5
dalinComment #6
dalinWhoops, created the patch from the wrong directory. Here's another go.
Comment #8
dalinNow with (hopefully) a passing test.
Comment #9
Bunty Badgujar CreditAttribution: Bunty Badgujar at Srijan | A Material+ Company for Drupal India Association commentedMoving to Need review as last submitted patch passes test cases.
Comment #10
Bunty Badgujar CreditAttribution: Bunty Badgujar at Srijan | A Material+ Company for Drupal India Association commentedAfter quick look to patch #8
Example output doesn't match with Patch. Following changes needed :-
should change to
and
+ throw new DirectoryNotReadyException("The specified file '$original_source' could not be copied because the destination directory $dirname is not properly configured. This may be caused by a problem with file or directory permissions.");
should change to
+ throw new DirectoryNotReadyException("The specified file '$original_source' could not be copied because the destination directory '$dirname' is not properly configured. This may be caused by a problem with file or directory permissions.");
Comment #11
mrinalini9 CreditAttribution: mrinalini9 at Srijan | A Material+ Company for Drupal India Association commentedComment #12
mrinalini9 CreditAttribution: mrinalini9 at Srijan | A Material+ Company for Drupal India Association commentedUpdated patch #8 as per the changes mentioned in #10, please review.
Comment #14
kishor_kolekar CreditAttribution: kishor_kolekar as a volunteer and at QED42 for Drupal India Association commentedComment #15
kishor_kolekar CreditAttribution: kishor_kolekar as a volunteer and at QED42 for Drupal India Association commented#8 patch looks good to me.
in my opnion @Bunty Badgujar I don't think we should not use string concatenation in
$this->logger->error
Comment #16
kishor_kolekar CreditAttribution: kishor_kolekar as a volunteer and at QED42 for Drupal India Association commentedComment #17
Bunty Badgujar CreditAttribution: Bunty Badgujar at Srijan | A Material+ Company for Drupal India Association commentedThanks @kishor kolekar for review. Its not string concatenation, I am talking about $dirname should be prefix and suffix with ' (aapostrophe). See issue discription.
Moving back to Need work as last submitted patch failed.
Comment #18
mrinalini9 CreditAttribution: mrinalini9 at Srijan | A Material+ Company for Drupal India Association commentedComment #19
mrinalini9 CreditAttribution: mrinalini9 at Srijan | A Material+ Company for Drupal India Association commentedFixed test case failure issue in #12, please review.
Comment #20
dalinComment #21
dalinComment #24
catchCommitted 264d89c and pushed to 9.1.x. Thanks!