Problem/Motivation

The following is no longer accurate

* This is a powerful function that in many ways performs like an advanced
* version of copy().
* - Checks if $source and $destination are valid and readable/writable.
* - If file already exists in $destination either the call will error out,
* replace the file or rename the file based on the $fileExists parameter.
* - If the $source and $destination are equal, the behavior depends on the
* $fileExists parameter.
* - Provides a fallback using realpaths if the move fails using stream
* wrappers. This can occur because PHP's copy() function does not properly
* support streams if open_basedir is enabled. See
* https://bugs.php.net/bug.php?id=60456

Proposed resolution

See changes in MR

Remaining tasks

Review
commit

User interface changes

API changes

Data model changes

Release notes snippet

Issue fork drupal-2843100

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

aaronbauman created an issue. See original summary.

aaronbauman’s picture

Status: Active » Needs review
StatusFileSize
new1.28 KB
aaronbauman’s picture

Issue summary: View changes
aaronbauman’s picture

Issue summary: View changes

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Munavijayalakshmi’s picture

Assigned: Unassigned » Munavijayalakshmi
StatusFileSize
new1.28 KB

There was error in patch. I've fixed it & added.

drupal-file_unmanaged_copy_docs-2843100.patch:19: trailing whitespace.
 *   will assign a new unique name (@see file_create_filename()). 
Checking patch core/includes/file.inc...
Applied patch core/includes/file.inc cleanly.
warning: 1 line adds whitespace errors.
Munavijayalakshmi’s picture

Assigned: Munavijayalakshmi » Unassigned
bander2’s picture

Status: Needs review » Reviewed & tested by the community

Looks good.

gábor hojtsy’s picture

Status: Reviewed & tested by the community » Needs work

Thanks all for working on this but I think this still needs some improvement.

+++ b/core/includes/file.inc
@@ -419,11 +419,12 @@ function file_valid_uri($uri) {
- * - If file already exists in $destination either the call will error out,
- *   replace the file or rename the file based on the $replace parameter.
- * - If the $source and $destination are equal, the behavior depends on the
- *   $replace parameter. FILE_EXISTS_REPLACE will error out. FILE_EXISTS_RENAME
- *   will rename the file until the $destination is unique.
+ * - If $source and $destination are equal, return false. Do not overwrite a
+ *   file with itself.
+ * - If file already exists in $destination, the behavior depends on the
+ *   $replace parameter. FILE_EXISTS_ERROR will return false,
+ *   FILE_EXISTS_REPLACE will replace the existing file, and FILE_EXISTS_RENAME
+ *   will assign a new unique name (@see file_create_filename()).

This looses "error out" which may mean it just logs an error, but that would still be useful to document (I guess keep documented even though it was/is misleadingly documented).

The new first item is not describing the behavior from the consumer/user side but from the function, which is in stark contrast to the item above and below.

gaurav.kapoor’s picture

Status: Needs work » Needs review
StatusFileSize
new1.39 KB
new949 bytes

Modified as per suggestion in #9.

dinesh18’s picture

Looks good to me. +1 to RTBC

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

tanubansal’s picture

Tested #10 on 9.1. It appears fine to me as well
RTBC + 1

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

abhijith s’s picture

Patch can't be applied on 9.2.x dev .Showing error

Checking patch core/includes/file.inc...
error: while searching for:
 *
 * This is a powerful function that in many ways performs like an advanced
 * version of copy().
 * - Checks if $source and $destination are valid and readable/writable.
 * - If file already exists in $destination either the call will error out,
 *   replace the file or rename the file based on the $replace parameter.
 * - If the $source and $destination are equal, the behavior depends on the
 *   $replace parameter. FILE_EXISTS_REPLACE will error out. FILE_EXISTS_RENAME
 *   will rename the file until the $destination is unique.
 * - Works around a PHP bug where copy() does not properly support streams if
 *   safe_mode or open_basedir are enabled.
 *   @see https://bugs.php.net/bug.php?id=60456

error: patch failed: core/includes/file.inc:428
error: core/includes/file.inc: patch does not apply
aaronbauman’s picture

Assigned: Unassigned » aaronbauman
Status: Needs review » Needs work
aaronbauman’s picture

Version: 9.2.x-dev » 8.9.x-dev
Assigned: aaronbauman » Unassigned
Status: Needs work » Needs review

This is N/A for D9, because it's deprecated as of 8.7
Version should not be updated past 8.9

#10 still applies.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev
larowlan’s picture

Status: Needs review » Needs work
Issue tags: +Bug Smash Initiative, +Needs reroll
immaculatexavier’s picture

Status: Needs work » Needs review
StatusFileSize
new1.58 KB

Patch for 9.3

larowlan’s picture

Priority: Normal » Minor
Status: Needs review » Needs work

file_unmanaged_copy was removed from core in Drupal 9.0 (deprecated in 8.7.0).

The new docs are on \Drupal\Core\File\FileSystemInterface::copy and that's where the updating should occur.

immaculatexavier’s picture

Status: Needs work » Needs review
StatusFileSize
new1.68 KB

Rerolled the Patch against 9.3.x. Please review
Updated the docs in \Drupal\Core\File\FileSystemInterface::copy

immaculatexavier’s picture

Issue tags: -Needs reroll
avpaderno’s picture

Status: Needs review » Needs work
+   * - If file already exists in $destination, the behavior depends on the
+   *   $replace parameter. FILE_EXISTS_ERROR will error out,
+   *   FILE_EXISTS_REPLACE will replace the existing file, and FILE_EXISTS_RENAME
+   *   will assign a new unique name (@see createFilename()).

If I understand the coding standards for @see, the method name must include the fully qualified name of its class. @see needs to be on its own line, which in this case means it should be placed after that list.

yogeshmpawar’s picture

Status: Needs work » Needs review
StatusFileSize
new2.22 KB
new1.41 KB

Addressed #30 with an interdiff.

avpaderno’s picture

Status: Needs review » Needs work

The method name must contain the class name, namespace included.

avpaderno’s picture

Status: Needs work » Needs review
StatusFileSize
new2.26 KB

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Arti Anil Pattewar’s picture

StatusFileSize
new1.01 MB

patch #33 applied cleanly on D9.4.x.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

aziza_a’s picture

StatusFileSize
new876.01 KB
new721.18 KB

patch #33 applied cleanly on D9.5.x.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs Review Queue Initiative

Change in #33 seems fine too me.

catch’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs issue summary update

I don't think this is right.

https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21File%21Fi... - this throws an exception if $source and $destination are the same.

Exception is also documented here: https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21File%21Fi...

Also the issue summary is still referencing the procedural functions that were removed a long time ago.

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone made their first commit to this issue’s fork.

quietone’s picture

Title: file_unmanaged_copy() documentation is inaccurate » FileSystemInterface::copy documentation is inaccurate
Issue summary: View changes
Status: Needs work » Needs review
Issue tags: -Needs issue summary update

Updated issue summary and created an MR.

VladimirAus made their first commit to this issue’s fork.

vladimiraus’s picture

Added example and updated $fileExists parameters.

jannakha’s picture

Status: Needs review » Reviewed & tested by the community

thanks for the fix

quietone’s picture

Status: Reviewed & tested by the community » Needs work

Oh, nice to see the quick response, thanks.

Left a comment on the MR that needs a response.

vladimiraus’s picture

Status: Needs work » Needs review

Thanks @quietone. Updated.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new1.28 KB

The Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

vladimiraus’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Needs work

Would agree with removing $file_system->prepareDirectory($directory, FileSystemInterface::CREATE_DIRECTORY); mainly because the sentence below the example mentions copying but nothing about needing to prepare the folder, which to my knowledge isn't always needed

vladimiraus’s picture

Status: Needs work » Needs review

Removed $file_system->prepareDirectory($directory, FileSystemInterface::CREATE_DIRECTORY); from example.

jannakha’s picture

Status: Needs review » Reviewed & tested by the community

Docs are updated as required.
RTBC.

quietone’s picture

I removed one blank line from the changes so this meets coding standards. And updated credit.

The changes are an improvement so if there is anything more let's put that in a followup. Leaving at RTBC.

  • nod_ committed d135a79d on 11.x
    Issue #2843100 by VladimirAus, quietone, immaculatexavier, yogeshmpawar...
nod_’s picture

Status: Reviewed & tested by the community » Fixed

Thanks for sorting out the credits.

Committed d135a79 and pushed to 11.x. Thanks!

Status: Fixed » Closed (fixed)

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