This function has not been updated for the new stream wrapper URIs in file.inc.. Thatfor it was broken and tried to give a 'normal' file system path as destination which ended up causing file_unmanaged_copy to complain it could not copy the file there (=> #573288: File.inc function documentation: clarify that several functions _must_ be fed a stream wrapper URI)- relevant code in file.inc:
// Assert that the destination contains a valid stream.
$destination_scheme = file_uri_scheme($destination);
if (!$destination_scheme || !file_stream_wrapper_valid_scheme($destination_scheme)) {
drupal_set_message(t('The specified file %file could not be copied, because the destination %destination is invalid. This is often caused by improper use of file_unmanaged_copy() or a missing stream wrapper.', array('%file' => $original_source, '%destination' => $destination)), 'error');
}
The first patch adds a testcase for fetching a remote file, the other one repairs system_retrieve_file() after which the tests pass. Hope i haven't missed anything, comments appreciated.
Comments
Comment #1
eMPee584 CreditAttribution: eMPee584 commentedboth patches combined => should pass the tests..
Comment #3
sunCan we remove the word "Drupal" from here?
The last one can be replaced with "site's default files scheme".
Does not wrap at 80 chars.
Improper indentation: "unique" should be located right below "FILE_...".
We also use colons (:) to separate option values from their descriptions (not hyphens).
Holy cow. Can we write that more readable by assigning the path differently in an if/else statement? :)
HTTP always all-uppercase.
You're sure there isn't a private files test already?
Wrong indentation of PHPDoc comment here.
This review is powered by Dreditor.
Comment #4
eMPee584 CreditAttribution: eMPee584 commentedThx for reviewing sun and sorry it took me so long. Synced my D7 up to date, checked the patch (and test) still works as intended and followed your recommendations. Regarding your question, yes tests for the file interface do exist, but the included tests really check something different. Maybe the three tests (check for correct path, then for file existence, then for correct file size) could be collapsed into only two, but..
?
Comment #5
eMPee584 CreditAttribution: eMPee584 commentedWhat a baaad issue title this has X)
Also might be a good idea to post what happens if you try to use system_retrieve_file wihout this fix:
The specified file temporary://file47942o could not be copied, because the destination sites/default/private/temp is invalid. This is often caused by improper use of file_unmanaged_copy() or a missing stream wrapper.
Comment #6
eMPee584 CreditAttribution: eMPee584 commented...btw what does drupal_http_request do when it gets fed .f.e an MP3 stream URL?.. mmh gonna try this..
Comment #8
eMPee584 CreditAttribution: eMPee584 commentedbumping this to critical - system module shouldn't really ship with code broken by default?
Comment #9
dcor CreditAttribution: dcor commentedJust a use case example - when uploading a new logo file or favicon icon to a theme... you get the following error message...
"The specified file temporary://logo_0.jpg could not be copied, because the destination logo.jpg is invalid. This is often caused by improper use of file_unmanaged_copy() or a missing stream wrapper."
So I'd say eMPee584 is right in bumping this to a critical issue.
I tried the attached patch which patched fine.. but didn't fix the issue any. Here's the error message again after applying the patch (not being a developer I hope that I'm right in assuming this is the right issue to post this in!)
The specified file temporary://logo_1.jpg could not be copied, because the destination logo.jpg is invalid. This is often caused by improper use of file_unmanaged_copy() or a missing stream wrapper.
So am I implying that this is a bigger issue? I haven't a clue.
Related issue - just found the actual issue for my problem but I'll leave this post here for your review just in case it is relevant: #605892: Cannot upload a logo
Comment #10
dcor CreditAttribution: dcor commentedComment #11
eMPee584 CreditAttribution: eMPee584 commented..so apparently the same problem exists in the system_theme_settings() and there's a patch for it aswell - nicce ;)
Comment #12
eMPee584 CreditAttribution: eMPee584 commentedrerolled..
am i wrong or is system_retrieve_file() supposed to be the primary function to allow modules the fetching of remote files?
Comment #13
sun.core CreditAttribution: sun.core commented#12: system-module-repair-system_retrieve_file-with-testcase-v3.patch queued for re-testing.
Comment #14
Dries CreditAttribution: Dries commentedThis looks good. Couple of smaller things:
'aswell' is not a valid word in English.
I find it odd that an API function uses drupal_set_message() but that is probably best left for another issue.
Should read 'HTTP file retrieval'.
Comment #15
eMPee584 CreditAttribution: eMPee584 commentedggrr if browser crashes one more #%! time i'm gRRrr---- ..
Well at least it's not within a core include (where it actually might belong?)...
Anyways, polished the text a further bit, g2g hopefully..
Comment #16
Dries CreditAttribution: Dries commentedCommitted to CVS HEAD. Thanks!
Comment #17
sunLovely! Thanks, eMPee584 for your patience! :)
Comment #18
eMPee584 CreditAttribution: eMPee584 commentedCool cool. Forward and BEYOND! ;D
Comment #20
Gábor HojtsyThis was not documented in the upgrade guide. Added at http://drupal.org/update/modules/6/7#system_retrieve_file
Comment #21
eMPee584 CreditAttribution: eMPee584 commentedTHX Gabor for filling the void!..
Comment #22
marco71 CreditAttribution: marco71 commentedHe sun are you a Javaman? lol