Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
afragen committed Apr 5, 2022
2 parents 65adf78 + ea64c6c commit 72a8d45
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 123 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#### [unreleased]

#### 10.9.0 / 2022-04-04
* revert usage of `move_dir()` and `is_virtualbox()` -- for now

#### 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
Expand Down
2 changes: 1 addition & 1 deletion git-updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.8.0
* Version: 10.9.0
* Author: Andy Fragen
* License: MIT
* Domain Path: /languages
Expand Down
4 changes: 2 additions & 2 deletions languages/git-updater.pot
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
# This file is distributed under the MIT.
msgid ""
msgstr ""
"Project-Id-Version: Git Updater 10.8.0\n"
"Project-Id-Version: Git Updater 10.9.0\n"
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/git-updater\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"POT-Creation-Date: 2022-04-04T04:35:59+00:00\n"
"POT-Creation-Date: 2022-04-05T00:02:21+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"
Expand Down
6 changes: 1 addition & 5 deletions src/Git_Updater/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -517,11 +517,7 @@ 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 ) {
if ( function_exists( 'move_dir' ) ) {
move_dir( $source, $new_source );
} else {
$this->move_dir( $source, $new_source );
}
$this->move( $source, $new_source );
}

return trailingslashit( $new_source );
Expand Down
157 changes: 44 additions & 113 deletions src/Git_Updater/Traits/GU_Trait.php
Original file line number Diff line number Diff line change
Expand Up @@ -688,140 +688,71 @@ public static function get_plugin_version() {
}

/**
* Moves a directory from one location to another via the rename() PHP function.
* If the renaming failed, falls back to copy_dir().
* Rename or recursive file copy and delete.
*
* Assumes that WP_Filesystem() has already been called and setup.
* 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()`.
*
* @since 6.1.0
* @param string $source File path of source.
* @param string $destination File path of destination.
*
* @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.
* @return bool True for success, false for failure.
*/
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 );
public function move( $source, $destination ) {
if ( $this->filesystem_move( $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 );
if ( is_dir( $destination ) && rename( $source, $destination ) ) {
return true;
}

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 );
// 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}" );
}
}
}

$result = copy_dir( $from, $to );

if ( ! is_wp_error( $result ) ) {
// Clear the source directory.
$wp_filesystem->delete( $from, true );
$iterator = new \FilesystemIterator( $source );
if ( ! $iterator->valid() ) { // True if directory is empty.
rmdir( $source );
}
closedir( $dir );

return true;
}

return $result;
return false;
}

/**
* Attempt to detect a VirtualBox environment.
*
* This attempts all known methods of detecting VirtualBox.
* Non-direct filesystem move.
*
* @global $wp_filesystem The filesystem.
* @uses $wp_filesystem->move() when FS_METHOD is not 'direct'
*
* @since 6.1.0
* @param string $source File path of source.
* @param string $destination File path of destination.
*
* @return bool Whether or not VirtualBox was detected.
* @return bool|void True on success, false on failure.
*/
public function is_virtualbox() {
public function filesystem_move( $source, $destination ) {
global $wp_filesystem;
static $is_virtualbox;

if ( null !== $is_virtualbox ) {
return $is_virtualbox;
}

// 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;
if ( 'direct' !== $wp_filesystem->method ) {
return $wp_filesystem->move( $source, $destination );
}

// Give up.
$is_virtualbox = false;

return $is_virtualbox;
return false;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions vendor/composer/installed.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
'type' => 'wordpress-plugin',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
'reference' => 'ae7f293bede95ab986886a5ee254a0b24fb705d0',
'reference' => '65adf789e4971eb3b453399a3179334f95f6fa55',
'name' => 'afragen/git-updater',
'dev' => true,
),
Expand All @@ -16,7 +16,7 @@
'type' => 'wordpress-plugin',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
'reference' => 'ae7f293bede95ab986886a5ee254a0b24fb705d0',
'reference' => '65adf789e4971eb3b453399a3179334f95f6fa55',
'dev_requirement' => false,
),
'afragen/singleton' => array(
Expand Down

0 comments on commit 72a8d45

Please sign in to comment.