Skip to content

Conversation

@costdev
Copy link
Contributor

@costdev costdev commented Jan 25, 2023

This PR adds directory support to WP_Filesystem_Direct::move() for consistency with the other WP_Filesystem_* classes.

This includes:

  • Updates to WP_Filesystem_Direct::move().
  • A new global function: wp_opcache_invalidate_directory(), to recursively call wp_opcache_invalidate().
  • A new wrapper function: move_dir(), for extender convenience and more informative failure reasons.
  • Tests for move_dir().
  • Tests for wp_opcache_invalidate_directory().

Testing instructions

Steps to test

  1. Ensure that WP_DEBUG and WP_DEBUG_LOG are set to true.
  2. Change this line to:
$result = move_dir( $source, $remote_destination, true );
  1. Navigate to Dashboard > Updates and update one or more plugins/themes.
  2. Navigate to Plugins > Installed plugins and update one or more plugins.
  3. Navigate to Appearance > Themes and update some themes.

Expected results

All updates should complete as normal, with no errors/warnings/notices in wp-content/debug.log.

Trac ticket: https://core.trac.wordpress.org/ticket/57375

@costdev costdev marked this pull request as ready for review January 25, 2023 23:37
@costdev costdev force-pushed the add_directory_support_to_wp_filesystem_direct_move branch 2 times, most recently from ccd19bd to 14cfb77 Compare January 26, 2023 00:50
@costdev costdev force-pushed the add_directory_support_to_wp_filesystem_direct_move branch from 14cfb77 to 20a411e Compare January 26, 2023 03:03
Copy link
Contributor

@peterwilsoncc peterwilsoncc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a few notes inline.

@costdev costdev force-pushed the add_directory_support_to_wp_filesystem_direct_move branch 2 times, most recently from 0602168 to cdefe50 Compare January 26, 2023 05:12
@costdev costdev force-pushed the add_directory_support_to_wp_filesystem_direct_move branch from 6ed97ca to 235bf29 Compare January 26, 2023 19:32
Copy link
Member

@afragen afragen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recently encountered an edge case where $from and $to differed only by a trailing slash. This resulted in the clearing of $to prior to rename() deleting the source. We could easily add a guard for that case as in the following.

	if ( trailingslashit( $from ) === trailingslashit( $to ) ) {
		return false;
	}

Would need to update @return also.

costdev#71

@costdev costdev force-pushed the add_directory_support_to_wp_filesystem_direct_move branch from 3892132 to 5378949 Compare January 30, 2023 10:21
@costdev costdev requested review from azaozz and peterwilsoncc and removed request for azaozz and peterwilsoncc January 30, 2023 18:53
Copy link
Member

@SergeyBiryukov SergeyBiryukov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the feedback appears to be addressed.

With no new concerns raised, I believe this is now ready for commit?

@costdev costdev force-pushed the add_directory_support_to_wp_filesystem_direct_move branch from 2f27c7f to 8aa303a Compare January 31, 2023 17:18
@costdev costdev force-pushed the add_directory_support_to_wp_filesystem_direct_move branch from 8aa303a to 809f893 Compare January 31, 2023 17:19
@costdev
Copy link
Contributor Author

costdev commented Jan 31, 2023

For clarity: The latest push was just to rebase on trunk and make some minor updates to test documentation 🙂

Copy link
Contributor

@peterwilsoncc peterwilsoncc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few more notes and a question.

This is in really good shape and I think it will be good for the first beta.

Co-authored-by: Sergey Biryukov <[email protected]>
Copy link
Member

@felixarntz felixarntz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@costdev @afragen Overall this looks very solid, though I have a few follow up questions / potential concerns. Please take a look.

Copy link
Contributor

@peterwilsoncc peterwilsoncc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I think this is ready.

@felixarntz The 200ms delay is a necessary evil due to excessive caching in some set ups (VirtualBox been the most likely to be hit via VVV, Chassis and others). Without it, the wrong files can be affected by multiple calls to move_dir() and cause fatal errors.

I think it's the least bad solution, and even with the delay the switch to move_dir() is substantially faster in my testing. I suspect the reason WP wasn't hitting the caching issue in the past was because copy_dir() is so slow.

@azaozz azaozz self-requested a review February 2, 2023 02:48
Copy link
Contributor

@azaozz azaozz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking this is ready too. Only the docblock updates for the other ::move() methods.

Copy link
Member

@felixarntz felixarntz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is good to commit. We can probably also commit #3963 right after. 🎉

@azaozz
Copy link
Contributor

azaozz commented Feb 3, 2023

@azaozz azaozz closed this Feb 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants