From bb6a63577c9e5f03ee3b411195fa12fbde99a51c Mon Sep 17 00:00:00 2001 From: Andy Fragen Date: Fri, 1 Apr 2022 22:19:16 -0700 Subject: [PATCH 1/3] use new move_dir() https://github.com/WordPress/wordpress-develop/pull/2225/files --- CHANGES.md | 1 + git-updater.php | 2 +- src/Git_Updater/Base.php | 6 +- src/Git_Updater/Traits/GU_Trait.php | 157 ++++++++++++++++++++-------- 4 files changed, 120 insertions(+), 46 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 21461fb39..950ee6373 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,4 +1,5 @@ #### [unreleased] +* use `move_dir()` and `is_virtualbox()` from [#51875](https://core.trac.wordpress.org/ticket/51857) [PR #2225](https://github.com/WordPress/wordpress-develop/pull/2225/files) #### 10.7.2 / 2022-03-31 * fix directory rename for single file plugin update diff --git a/git-updater.php b/git-updater.php index 92a33c24a..d13a4fef1 100644 --- a/git-updater.php +++ b/git-updater.php @@ -12,7 +12,7 @@ * Plugin Name: Git Updater * Plugin URI: https://git-updater.com * Description: A plugin to automatically update GitHub hosted plugins, themes, and language packs. Additional API plugins available for Bitbucket, GitLab, Gitea, and Gist. - * Version: 10.7.2 + * Version: 10.7.2.1 * Author: Andy Fragen * License: MIT * Domain Path: /languages diff --git a/src/Git_Updater/Base.php b/src/Git_Updater/Base.php index 619965c5a..3c949985a 100644 --- a/src/Git_Updater/Base.php +++ b/src/Git_Updater/Base.php @@ -517,7 +517,11 @@ public function upgrader_source_selection( $source, $remote_source, $upgrader, $ $new_source = $this->fix_misnamed_directory( $new_source, $remote_source, $upgrader_object, $slug ); if ( $source !== $new_source ) { - $this->move( $source, $new_source ); + if ( function_exists( 'move_dir' ) ) { + move_dir( $source, $new_source ); + } else { + $this->move_dir( $source, $new_source ); + } } return trailingslashit( $new_source ); diff --git a/src/Git_Updater/Traits/GU_Trait.php b/src/Git_Updater/Traits/GU_Trait.php index 61e1d6b5e..ab19de2c5 100644 --- a/src/Git_Updater/Traits/GU_Trait.php +++ b/src/Git_Updater/Traits/GU_Trait.php @@ -688,71 +688,140 @@ public static function get_plugin_version() { } /** - * Rename or recursive file copy and delete. + * Moves a directory from one location to another via the rename() PHP function. + * If the renaming failed, falls back to copy_dir(). * - * This is more versatile than `$wp_filesystem->move()` for FS_METHOD 'direct'. - * It moves/renames directories as well as files. - * Fix for https://github.com/afragen/github-updater/issues/826, - * strange failure of `rename()`. + * Assumes that WP_Filesystem() has already been called and setup. * - * @param string $source File path of source. - * @param string $destination File path of destination. + * @since 6.1.0 * - * @return bool True for success, false for failure. + * @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass. + * + * @param string $from Source directory. + * @param string $to Destination directory. + * + * @return true|WP_Error True on success, WP_Error on failure. */ - public function move( $source, $destination ) { - if ( $this->filesystem_move( $source, $destination ) ) { - return true; + public function move_dir( $from, $to ) { + global $wp_filesystem; + + $result = false; + + /* + * Skip the rename() call on VirtualBox environments. + * There are some known issues where rename() can fail on shared folders + * without reporting an error properly. + * + * More details: + * https://www.virtualbox.org/ticket/8761#comment:24 + * https://www.virtualbox.org/ticket/17971 + */ + if ( 'direct' === $wp_filesystem->method && ! $this->is_virtualbox() ) { + $wp_filesystem->rmdir( $to ); + + $result = @rename( $from, $to ); } - if ( is_dir( $destination ) && rename( $source, $destination ) ) { - return true; + + // Non-direct filesystems use some version of rename without a fallback. + if ( 'direct' !== $wp_filesystem->method ) { + $result = $wp_filesystem->move( $from, $to ); } - // phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition.Found, Squiz.PHP.DisallowMultipleAssignments.FoundInControlStructure - if ( $dir = opendir( $source ) ) { - if ( ! file_exists( $destination ) ) { - mkdir( $destination ); - } - $source = untrailingslashit( $source ); - // phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition - while ( false !== ( $file = readdir( $dir ) ) ) { - if ( ( '.' !== $file ) && ( '..' !== $file ) && "{$source}/{$file}" !== $destination ) { - if ( is_dir( "{$source}/{$file}" ) ) { - $this->move( "{$source}/{$file}", "{$destination}/{$file}" ); - } else { - copy( "{$source}/{$file}", "{$destination}/{$file}" ); - unlink( "{$source}/{$file}" ); - } + + if ( ! $result ) { + if ( ! $wp_filesystem->is_dir( $to ) ) { + if ( ! $wp_filesystem->mkdir( $to, FS_CHMOD_DIR ) ) { + return new WP_Error( 'mkdir_failed_move_dir', __( 'Could not create directory.' ), $to ); } } - $iterator = new \FilesystemIterator( $source ); - if ( ! $iterator->valid() ) { // True if directory is empty. - rmdir( $source ); - } - closedir( $dir ); - return true; + $result = copy_dir( $from, $to ); + + if ( ! is_wp_error( $result ) ) { + // Clear the source directory. + $wp_filesystem->delete( $from, true ); + } } - return false; + return $result; } /** - * Non-direct filesystem move. + * Attempt to detect a VirtualBox environment. + * + * This attempts all known methods of detecting VirtualBox. * - * @uses $wp_filesystem->move() when FS_METHOD is not 'direct' + * @global $wp_filesystem The filesystem. * - * @param string $source File path of source. - * @param string $destination File path of destination. + * @since 6.1.0 * - * @return bool|void True on success, false on failure. + * @return bool Whether or not VirtualBox was detected. */ - public function filesystem_move( $source, $destination ) { + public function is_virtualbox() { global $wp_filesystem; - if ( 'direct' !== $wp_filesystem->method ) { - return $wp_filesystem->move( $source, $destination ); + static $is_virtualbox; + + if ( null !== $is_virtualbox ) { + return $is_virtualbox; } - return false; + // Detection via filter. + if ( apply_filters( 'is_virtualbox', false ) ) { + $is_virtualbox = true; + return $is_virtualbox; + } + + // Detection via Composer. + if ( function_exists( 'getenv' ) && 'virtualbox' === getenv( 'COMPOSER_RUNTIME_ENV' ) ) { + $is_virtualbox = true; + return $is_virtualbox; + } + + $virtualbox_unames = [ 'vvv' ]; + + // Detection via `php_uname()`. + if ( function_exists( 'php_uname' ) && in_array( php_uname( 'n' ), $virtualbox_unames, true ) ) { + $is_virtualbox = true; + return $is_virtualbox; + } + + /* + * Vagrant can use alternative providers. + * This isn't reliable without some additional check(s). + */ + $virtualbox_usernames = [ 'vagrant' ]; + + // Detection via user name with POSIX. + if ( function_exists( 'posix_getpwuid' ) && function_exists( 'posix_geteuid' ) ) { + $user = posix_getpwuid( posix_geteuid() ); + + if ( $user && in_array( $user['name'], $virtualbox_usernames, true ) ) { + $is_virtualbox = true; + return $is_virtualbox; + } + } + + // Initialize the filesystem if not set. + if ( ! $wp_filesystem ) { + require_once ABSPATH . '/wp-admin/includes/file.php'; + WP_Filesystem(); + } + + // Detection via file owner. + if ( in_array( $wp_filesystem->owner( __FILE__ ), $virtualbox_usernames, true ) ) { + $is_virtualbox = true; + return $is_virtualbox; + } + + // Detection via file group. + if ( in_array( $wp_filesystem->group( __FILE__ ), $virtualbox_usernames, true ) ) { + $is_virtualbox = true; + return $is_virtualbox; + } + + // Give up. + $is_virtualbox = false; + + return $is_virtualbox; } /** From 61c5ed5215e2b60286bd3d03896fbbdb8d8cd711 Mon Sep 17 00:00:00 2001 From: Andy Fragen Date: Sun, 3 Apr 2022 21:29:09 -0700 Subject: [PATCH 2/3] revert single file plugin "fix" --- CHANGES.md | 1 + git-updater.php | 2 +- src/Git_Updater/Base.php | 10 ---------- 3 files changed, 2 insertions(+), 11 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 950ee6373..1b605b2bc 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,6 @@ #### [unreleased] * use `move_dir()` and `is_virtualbox()` from [#51875](https://core.trac.wordpress.org/ticket/51857) [PR #2225](https://github.com/WordPress/wordpress-develop/pull/2225/files) +* revert fix directory rename for single file plugin update #### 10.7.2 / 2022-03-31 * fix directory rename for single file plugin update diff --git a/git-updater.php b/git-updater.php index d13a4fef1..3104fd0cb 100644 --- a/git-updater.php +++ b/git-updater.php @@ -12,7 +12,7 @@ * Plugin Name: Git Updater * Plugin URI: https://git-updater.com * Description: A plugin to automatically update GitHub hosted plugins, themes, and language packs. Additional API plugins available for Bitbucket, GitLab, Gitea, and Gist. - * Version: 10.7.2.1 + * Version: 10.7.2.2 * Author: Andy Fragen * License: MIT * Domain Path: /languages diff --git a/src/Git_Updater/Base.php b/src/Git_Updater/Base.php index 3c949985a..3ad8231a9 100644 --- a/src/Git_Updater/Base.php +++ b/src/Git_Updater/Base.php @@ -549,16 +549,6 @@ private function fix_misnamed_directory( $new_source, $remote_source, $upgrader_ $new_source = trailingslashit( $remote_source ) . $slug; } - // Move single file plugins into their own directory. - $single_file_plugin = isset( $config['.'] ) ? $config['.'] : false; - if ( $single_file_plugin - && ( \property_exists( $single_file_plugin, 'slug' ) && '.' === $single_file_plugin->slug ) - ) { - // Strip `.php` from the filename. - $slug = substr( $single_file_plugin->file, 0, -4 ); - $new_source = trailingslashit( $remote_source ) . $slug; - } - return $new_source; } From 113158c2728597352617929a46aa9b3000f28a95 Mon Sep 17 00:00:00 2001 From: Andy Fragen Date: Sun, 3 Apr 2022 21:38:57 -0700 Subject: [PATCH 3/3] release --- CHANGES.md | 2 ++ composer.lock | 2 +- git-updater.php | 2 +- languages/git-updater.pot | 20 ++++++++++---------- vendor/composer/InstalledVersions.php | 2 ++ vendor/composer/autoload_classmap.php | 2 +- vendor/composer/autoload_namespaces.php | 2 +- vendor/composer/autoload_psr4.php | 2 +- vendor/composer/autoload_real.php | 25 +++---------------------- vendor/composer/installed.json | 2 +- vendor/composer/installed.php | 6 +++--- 11 files changed, 26 insertions(+), 41 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 1b605b2bc..ba6923ba7 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,4 +1,6 @@ #### [unreleased] + +#### 10.8.0 / 2022-04-03 * use `move_dir()` and `is_virtualbox()` from [#51875](https://core.trac.wordpress.org/ticket/51857) [PR #2225](https://github.com/WordPress/wordpress-develop/pull/2225/files) * revert fix directory rename for single file plugin update diff --git a/composer.lock b/composer.lock index c4f9919b0..2e84adac8 100644 --- a/composer.lock +++ b/composer.lock @@ -305,5 +305,5 @@ "php": ">=5.6" }, "platform-dev": [], - "plugin-api-version": "2.2.0" + "plugin-api-version": "2.3.0" } diff --git a/git-updater.php b/git-updater.php index 3104fd0cb..6722d091a 100644 --- a/git-updater.php +++ b/git-updater.php @@ -12,7 +12,7 @@ * Plugin Name: Git Updater * Plugin URI: https://git-updater.com * Description: A plugin to automatically update GitHub hosted plugins, themes, and language packs. Additional API plugins available for Bitbucket, GitLab, Gitea, and Gist. - * Version: 10.7.2.2 + * Version: 10.8.0 * Author: Andy Fragen * License: MIT * Domain Path: /languages diff --git a/languages/git-updater.pot b/languages/git-updater.pot index 924d9fbf9..b3bbb8888 100644 --- a/languages/git-updater.pot +++ b/languages/git-updater.pot @@ -2,14 +2,14 @@ # This file is distributed under the MIT. msgid "" msgstr "" -"Project-Id-Version: Git Updater 10.7.1\n" +"Project-Id-Version: Git Updater 10.8.0\n" "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/git-updater\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"POT-Creation-Date: 2022-03-12T22:24:53+00:00\n" +"POT-Creation-Date: 2022-04-04T04:35:59+00:00\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "X-Generator: WP-CLI 2.6.0\n" "X-Domain: git-updater\n" @@ -110,35 +110,35 @@ msgstr "" msgid "Free Trial" msgstr "" -#: src/Git_Updater/API/GitHub_API.php:354 +#: src/Git_Updater/API/GitHub_API.php:351 msgid "GitHub Personal Access Token" msgstr "" -#: src/Git_Updater/API/GitHub_API.php:361 +#: src/Git_Updater/API/GitHub_API.php:358 msgid "GitHub.com Access Token" msgstr "" -#: src/Git_Updater/API/GitHub_API.php:377 +#: src/Git_Updater/API/GitHub_API.php:374 msgid "GitHub Private Settings" msgstr "" -#: src/Git_Updater/API/GitHub_API.php:404 +#: src/Git_Updater/API/GitHub_API.php:401 msgid "Enter your GitHub Access Token. Leave empty for public repositories." msgstr "" -#: src/Git_Updater/API/GitHub_API.php:411 +#: src/Git_Updater/API/GitHub_API.php:408 msgid "Enter your personal GitHub.com or GitHub Enterprise Access Token to avoid API access limits." msgstr "" -#: src/Git_Updater/API/GitHub_API.php:422 +#: src/Git_Updater/API/GitHub_API.php:419 msgid "GitHub Access Token" msgstr "" -#: src/Git_Updater/API/GitHub_API.php:436 +#: src/Git_Updater/API/GitHub_API.php:433 msgid "GitHub" msgstr "" -#: src/Git_Updater/API/GitHub_API.php:450 +#: src/Git_Updater/API/GitHub_API.php:447 msgid "Enter GitHub Access Token for private GitHub repositories." msgstr "" diff --git a/vendor/composer/InstalledVersions.php b/vendor/composer/InstalledVersions.php index d50e0c9fc..41bc143c1 100644 --- a/vendor/composer/InstalledVersions.php +++ b/vendor/composer/InstalledVersions.php @@ -21,6 +21,8 @@ * See also https://getcomposer.org/doc/07-runtime.md#installed-versions * * To require its presence, you can require `composer-runtime-api ^2.0` + * + * @final */ class InstalledVersions { diff --git a/vendor/composer/autoload_classmap.php b/vendor/composer/autoload_classmap.php index c1d03577c..49f4bc5d0 100644 --- a/vendor/composer/autoload_classmap.php +++ b/vendor/composer/autoload_classmap.php @@ -2,7 +2,7 @@ // autoload_classmap.php @generated by Composer -$vendorDir = dirname(dirname(__FILE__)); +$vendorDir = dirname(__DIR__); $baseDir = dirname($vendorDir); return array( diff --git a/vendor/composer/autoload_namespaces.php b/vendor/composer/autoload_namespaces.php index 2357cf95c..20c027f22 100644 --- a/vendor/composer/autoload_namespaces.php +++ b/vendor/composer/autoload_namespaces.php @@ -2,7 +2,7 @@ // autoload_namespaces.php @generated by Composer -$vendorDir = dirname(dirname(__FILE__)); +$vendorDir = dirname(__DIR__); $baseDir = dirname($vendorDir); return array( diff --git a/vendor/composer/autoload_psr4.php b/vendor/composer/autoload_psr4.php index c30ac6d59..db80e7a8d 100644 --- a/vendor/composer/autoload_psr4.php +++ b/vendor/composer/autoload_psr4.php @@ -2,7 +2,7 @@ // autoload_psr4.php @generated by Composer -$vendorDir = dirname(dirname(__FILE__)); +$vendorDir = dirname(__DIR__); $baseDir = dirname($vendorDir); return array( diff --git a/vendor/composer/autoload_real.php b/vendor/composer/autoload_real.php index a9b469226..592ea16df 100644 --- a/vendor/composer/autoload_real.php +++ b/vendor/composer/autoload_real.php @@ -25,30 +25,11 @@ public static function getLoader() require __DIR__ . '/platform_check.php'; spl_autoload_register(array('ComposerAutoloaderInita27e6a3df8c435e2b136f961f0442be2', 'loadClassLoader'), true, true); - self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__))); + self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__)); spl_autoload_unregister(array('ComposerAutoloaderInita27e6a3df8c435e2b136f961f0442be2', 'loadClassLoader')); - $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded()); - if ($useStaticLoader) { - require __DIR__ . '/autoload_static.php'; - - call_user_func(\Composer\Autoload\ComposerStaticInita27e6a3df8c435e2b136f961f0442be2::getInitializer($loader)); - } else { - $map = require __DIR__ . '/autoload_namespaces.php'; - foreach ($map as $namespace => $path) { - $loader->set($namespace, $path); - } - - $map = require __DIR__ . '/autoload_psr4.php'; - foreach ($map as $namespace => $path) { - $loader->setPsr4($namespace, $path); - } - - $classMap = require __DIR__ . '/autoload_classmap.php'; - if ($classMap) { - $loader->addClassMap($classMap); - } - } + require __DIR__ . '/autoload_static.php'; + \Composer\Autoload\ComposerStaticInita27e6a3df8c435e2b136f961f0442be2::getInitializer($loader)(); $loader->register(true); diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json index 3cbfe4cf9..04bedba5a 100644 --- a/vendor/composer/installed.json +++ b/vendor/composer/installed.json @@ -304,6 +304,6 @@ "install-path": "../freemius/wordpress-sdk" } ], - "dev": false, + "dev": true, "dev-package-names": [] } diff --git a/vendor/composer/installed.php b/vendor/composer/installed.php index 9da9e0531..9e8e8de9a 100644 --- a/vendor/composer/installed.php +++ b/vendor/composer/installed.php @@ -5,9 +5,9 @@ 'type' => 'wordpress-plugin', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), - 'reference' => 'd2ddce8572a1448647debadb6aa8daaabfcb9ea2', + 'reference' => '61c5ed5215e2b60286bd3d03896fbbdb8d8cd711', 'name' => 'afragen/git-updater', - 'dev' => false, + 'dev' => true, ), 'versions' => array( 'afragen/git-updater' => array( @@ -16,7 +16,7 @@ 'type' => 'wordpress-plugin', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), - 'reference' => 'd2ddce8572a1448647debadb6aa8daaabfcb9ea2', + 'reference' => '61c5ed5215e2b60286bd3d03896fbbdb8d8cd711', 'dev_requirement' => false, ), 'afragen/singleton' => array(