Skip to content

fix[faustwp]: (#2311) clean up uploaded blockset zip when extraction fails#2338

Open
latenighthackathon wants to merge 1 commit intowpengine:canaryfrom
latenighthackathon:fix/faustwp-blockset-cleanup
Open

fix[faustwp]: (#2311) clean up uploaded blockset zip when extraction fails#2338
latenighthackathon wants to merge 1 commit intowpengine:canaryfrom
latenighthackathon:fix/faustwp-blockset-cleanup

Conversation

@latenighthackathon
Copy link
Copy Markdown
Contributor

Summary

When unzip_uploaded_file() returns a WP_Error in process_and_replace_blocks(), the uploaded .zip stays behind in the target directory. Repeat failures accumulate dead files.

This PR deletes the target file before returning the error so the upload slot stays clean. Mirrors the existing cleanup_temp_directory() call on the success path.

Related Issue

Closes #2311

Split out from #2312 per @josephfusco's review feedback — the hash_equals() security hardening stays on #2312 so each change can be reviewed and reverted independently.

Confirm the issue

# The success path cleans up via cleanup_temp_directory(); the error path did not.
grep -n "cleanup_temp_directory\|return \$unzip_result" plugins/faustwp/includes/blocks/functions.php
# Expected on canary (before fix):
#   54:    $unzip_result = unzip_uploaded_file( $target_file, $dirs['target'] );
#   56:        return $unzip_result;       ← no delete of $target_file
#   59:    cleanup_temp_directory( $wp_filesystem, $dirs['temp'] );

Confirm the fix

# After this PR, the error branch explicitly deletes the uploaded zip.
sed -n '54,58p' plugins/faustwp/includes/blocks/functions.php
# Expected:
#   $unzip_result = unzip_uploaded_file( $target_file, $dirs['target'] );
#   if ( is_wp_error( $unzip_result ) ) {
#       $wp_filesystem->delete( $target_file );
#       return $unzip_result;
#   }

Run the test suite

# PHPCS for the touched file
npm run phpcs --prefix plugins/faustwp -- includes/blocks/functions.php

# PHPUnit for the blocks module
npm run test:php --prefix plugins/faustwp -- --filter=Blocks

Checklist

  • Targets canary
  • Changeset added (@faustwp/wordpress-plugin patch)
  • Commit is signed (SSH)
  • Semantic commit prefix with issue reference

…raction fails

When unzip_uploaded_file() returns a WP_Error in process_and_replace_blocks(),
the uploaded zip was left behind in the target directory. On repeat
failures this accumulates dead files on disk.

Delete the target file before returning the error so the upload slot
stays clean. Mirrors the existing cleanup_temp_directory() call on the
success path.

Split out from wpengine#2312 per @josephfusco review feedback — the hash_equals
security hardening half stays on that PR so each can be reviewed and
reverted independently.
@latenighthackathon latenighthackathon requested a review from a team as a code owner April 21, 2026 03:28
@headless-platform-by-wp-engine
Copy link
Copy Markdown

Currently, we do not support the creation of preview deployments based on changes coming from forked repositories.
Learn more about preview environments in our documentation.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 21, 2026

🦋 Changeset detected

Latest commit: 6295806

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@faustwp/wordpress-plugin Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

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.

fix[faustwp]: uploaded blockset file not cleaned up when extraction fails

1 participant