Skip to content

Hash the directory name of a package on install.#227

Merged
afragen merged 16 commits intofairpm:mainfrom
costdev:move_package_on_install
Dec 17, 2025
Merged

Hash the directory name of a package on install.#227
afragen merged 16 commits intofairpm:mainfrom
costdev:move_package_on_install

Conversation

@costdev
Copy link
Copy Markdown
Member

@costdev costdev commented Aug 19, 2025

This PR ensures that the directory name of a FAIR package is renamed to slug-didhash on installation.

In particular, this deals with the installation of a package without knowing its DID in advance. For example, when uploading the ZIP file of a plugin or theme.

See #228

@costdev costdev requested a review from afragen August 19, 2025 20:46
@costdev costdev force-pushed the move_package_on_install branch from 6c0bbec to c8497ef Compare August 19, 2025 20:54
@afragen
Copy link
Copy Markdown
Contributor

afragen commented Aug 20, 2025

We already do this on direct install,

function rename_source_selection( string $source, string $remote_source, WP_Upgrader $upgrader ) {
global $wp_filesystem;
$did = wp_cache_get( Admin\ACTION_INSTALL_DID );
if ( ! $did ) {
return $source;
}
$metadata = fetch_package_metadata( $did );
if ( is_wp_error( $metadata ) ) {
return $metadata;
}
// Sanity check.
if ( $upgrader->new_plugin_data['Name'] !== $metadata->name ) {
return $source;
}
if ( str_contains( $source, get_did_hash( $did ) ) && basename( $source ) === $metadata->slug ) {
return $source;
}
$new_source = trailingslashit( $remote_source ) . $metadata->slug . '-' . get_did_hash( $did );
if ( trailingslashit( strtolower( $source ) ) !== trailingslashit( strtolower( $new_source ) ) ) {
$wp_filesystem->move( $source, $new_source, true );
}
return trailingslashit( $new_source );
}

@costdev
Copy link
Copy Markdown
Member Author

costdev commented Aug 20, 2025

That covers the "Direct Install" tab, whereas this covers the "Upload ZIP" or wp plugin install <URL|path/to/zip> install paths.

@Ipstenu
Copy link
Copy Markdown
Contributor

Ipstenu commented Oct 27, 2025

@costdev Where are we here? Is this ready for 1.1?

@Ipstenu Ipstenu added question Further information is requested enhancement New feature or request labels Oct 27, 2025
In particular, this deals with the installation of a package without knowing its DID in advance. For example, when uploading the ZIP file of a plugin or theme.

Signed-off-by: costdev <79332690+costdev@users.noreply.github.com>
Signed-off-by: costdev <79332690+costdev@users.noreply.github.com>
Signed-off-by: costdev <79332690+costdev@users.noreply.github.com>
Signed-off-by: costdev <79332690+costdev@users.noreply.github.com>
@costdev costdev force-pushed the move_package_on_install branch from 2ec0043 to ea638e1 Compare October 27, 2025 19:23
@costdev
Copy link
Copy Markdown
Member Author

costdev commented Oct 27, 2025

@Ipstenu Just rebased the PR branch on main. It's ready for testing again.

🧪 Test this PR on Playground

@afragen
Copy link
Copy Markdown
Contributor

afragen commented Oct 28, 2025

I think https://github.com/afragen/fair-plugin/tree/rename-theme-on-download also solves issue with at least some code reuse.

afragen added a commit to afragen/fair-plugin that referenced this pull request Nov 17, 2025
Signed-off-by: Andy Fragen <andy@thefragens.com>
 Fixes fairpm#227
@afragen afragen added the needs review Probably ready for work, but needs eyes to double check. label Nov 17, 2025
@afragen afragen closed this Dec 7, 2025
@afragen afragen reopened this Dec 11, 2025
@costdev costdev added this to the 1.3 milestone Dec 11, 2025
afragen and others added 2 commits December 13, 2025 09:33
Co-authored-by: Colin Stewart <79332690+costdev@users.noreply.github.com>
Signed-off-by: Andy Fragen <andy@thefragens.com>
Co-authored-by: Colin Stewart <79332690+costdev@users.noreply.github.com>
Signed-off-by: Andy Fragen <andy@thefragens.com>
Co-authored-by: Andy Fragen <andy@thefragens.com>
Signed-off-by: Colin Stewart <79332690+costdev@users.noreply.github.com>
Signed-off-by: Colin Stewart <79332690+costdev@users.noreply.github.com>
@afragen
Copy link
Copy Markdown
Contributor

afragen commented Dec 13, 2025

costdev#8 to move from inc/updater to inc/packages

Signed-off-by: Andy Fragen <andy@thefragens.com>
Signed-off-by: Andy Fragen <andy@thefragens.com>
Signed-off-by: Andy Fragen <andy@thefragens.com>
@costdev costdev linked an issue Dec 14, 2025 that may be closed by this pull request
When the request fails or there's no slug,
'-didhash' will be appended to the directory name
in a best-available attempt at de-duplication.

Signed-off-by: costdev <79332690+costdev@users.noreply.github.com>
Signed-off-by: costdev <79332690+costdev@users.noreply.github.com>
This is already performed in get_package_metadata().

Signed-off-by: costdev <79332690+costdev@users.noreply.github.com>
Signed-off-by: costdev <79332690+costdev@users.noreply.github.com>
@afragen afragen merged commit bbe8aac into fairpm:main Dec 17, 2025
61 of 90 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request needs review Probably ready for work, but needs eyes to double check. question Further information is requested

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Handle "Upload ZIP" and WP-CLI install location

3 participants