Skip to content

πŸ› bones deploy reports 'βœ… Deploy completed!' when the destination's parent folder doesn't existΒ #139

Closed

Description

@gfazioli

src/Console/bin/bones, xcopy() L2995-L2998

// Make destination directory
if (!is_dir($dest)) {
  mkdir($dest, $permissions);
}

mkdir() is not recursive and its result isn't checked. When the parent of the deploy path doesn't exist, the destination folder is never created, so every nested mkdir() and every copy() fails with a PHP warning. Nothing reports the failure: the recursion drops each call's result (L3010), the directory branch returns true whatever happened inside it (L3016), and deploy() ignores the top-level result (L2803) and prints βœ… Deploy completed! (L2857) with exit status 0.

The post-copy check doesn't catch it either: assertAutoloadedFilesShipped() returns early when vendor/composer/autoload_files.php is missing from the destination (L3179), which is exactly the state an empty deploy leaves.

Reproduce

v3.2.0 (the console is identical to master at a27ef46), PHP 8.2.34, macOS:

php bones deploy /tmp/missing-parent/my-plugin --no-build
echo $?                   # 0
ls /tmp/missing-parent    # No such file or directory

For a plugin whose deploy is 221 files, the output is 76 mkdir(): No such file or directory warnings and 221 copy(…): Failed to open stream: No such file or directory warnings, followed by:

βœ… Deploy completed!
πŸš€ You can now deploy the plugin from the path: /tmp/missing-parent/my-plugin

How it showed up

Reproducing a Docker image build by hand. The Dockerfile creates the parent folder before running php bones deploy /package/<plugin> --no-build; the local re-run didn't, and only counting the files at the destination told the two runs apart.

Suggestion

Either create the missing parents, as mkdir -p would:

if (!is_dir($dest) && !mkdir($dest, $permissions, true) && !is_dir($dest)) {
  return false;
}

or refuse a destination whose parent doesn't exist up front, next to the other checks in assertSafeDeployDestination().

Either way, a failed mkdir() or copy() should end the deploy with exit 1. Propagating the result through the recursion needs care: xcopy() also returns false for a file it skips on purpose (dotfiles and the skip list), so today false means both "skipped" and "failed".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions