dist-archive-command icon indicating copy to clipboard operation
dist-archive-command copied to clipboard

Fails when scanning broken symlinks

Open BrianHenryIE opened this issue 2 years ago • 2 comments

Bug Report

Describe the current, buggy behavior

.distignore

...
/wp-content
...

Project files:

...
wp-content/plugins/woocommerce-gateway-dummy    // broken symlink
...
Fatal error: Uncaught Inmarelibero\GitIgnoreChecker\Exception\InvalidArgumentException: Path "/Users/brianhenry/Sites/bh-wp-bitcoin-gateway/wp-content/plugins/woocommerce-gateway-dummy" does not exist. in /Users/brianhenry/Sites/bh-wp-bitcoin-gateway/vendor/inmarelibero/gitignore-checker/src/Utils/PathUtils.php:86
Stack trace:
#0 /Users/brianhenry/Sites/bh-wp-bitcoin-gateway/vendor/inmarelibero/gitignore-checker/src/Model/RelativePath.php(64): Inmarelibero\GitIgnoreChecker\Utils\PathUtils::absolutePathIsValid('/Users/brianhen...')
#1 /Users/brianhenry/Sites/bh-wp-bitcoin-gateway/vendor/inmarelibero/gitignore-checker/src/Model/RelativePath.php(41): Inmarelibero\GitIgnoreChecker\Model\RelativePath->setPath('/wp-content/plu...')
#2 /Users/brianhenry/Sites/bh-wp-bitcoin-gateway/vendor/inmarelibero/gitignore-checker/src/GitIgnoreChecker.php(71): Inmarelibero\GitIgnoreChecker\Model\RelativePath->__construct(Object(Inmarelibero\GitIgnoreChecker\Model\Repository), '/wp-content/plu...')
#3 /Users/brianhenry/Sites/bh-wp-bitcoin-gateway/vendor/wp-cli/dist-archive-command/src/Dist_Archive_Command.php(444): Inmarelibero\GitIgnoreChecker\GitIgnoreChecker->isPathIgnored('/wp-content/plu...')
#4 /Users/brianhenry/Sites/bh-wp-bitcoin-gateway/vendor/wp-cli/dist-archive-command/src/Dist_Archive_Command.php(165): Dist_Archive_Command->get_file_list('/Users/brianhen...')
#5 [internal function]: Dist_Archive_Command->__invoke(Array, Array)
#6 /Users/brianhenry/Sites/bh-wp-bitcoin-gateway/vendor/wp-cli/wp-cli/php/WP_CLI/Dispatcher/CommandFactory.php(100): call_user_func(Array, Array, Array)
#7 [internal function]: WP_CLI\Dispatcher\CommandFactory::WP_CLI\Dispatcher\{closure}(Array, Array)
#8 /Users/brianhenry/Sites/bh-wp-bitcoin-gateway/vendor/wp-cli/wp-cli/php/WP_CLI/Dispatcher/Subcommand.php(488): call_user_func(Object(Closure), Array, Array)
#9 /Users/brianhenry/Sites/bh-wp-bitcoin-gateway/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(436): WP_CLI\Dispatcher\Subcommand->invoke(Array, Array, Array)
#10 /Users/brianhenry/Sites/bh-wp-bitcoin-gateway/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(459): WP_CLI\Runner->run_command(Array, Array)
#11 /Users/brianhenry/Sites/bh-wp-bitcoin-gateway/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(136): WP_CLI\Runner->run_command_and_exit()

Describe what you would expect as the correct outcome

It should handle this gracefully – it should only be scanning the excluded directories for .distignore files that act to include a subdir of an included dir. The broken symlink shouldn't be fatal for dist-ignore-command.

Let us know what environment you are running this on

OS:	Darwin 23.1.0 Darwin Kernel Version 23.1.0: Mon Oct  9 21:28:12 PDT 2023; root:xnu-10002.41.9~6/RELEASE_ARM64_T8103 arm64
Shell:	/bin/zsh
PHP binary:	/opt/homebrew/Cellar/[email protected]/8.0.30_1/bin/php
PHP version:	8.0.30
php.ini used:	/opt/homebrew/etc/php/8.0/php.ini
MySQL binary:	/opt/homebrew/bin/mysql
MySQL version:	mysql from 11.1.2-MariaDB, client 15.2 for osx10.18 (arm64) using  EditLine wrapper
SQL modes:	STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
WP-CLI root dir:	phar://wp-cli.phar/vendor/wp-cli/wp-cli
WP-CLI vendor dir:	phar://wp-cli.phar/vendor
WP_CLI phar path:	/Users/brianhenry/Sites/bh-wp-bitcoin-gateway
WP-CLI packages dir:	/Users/brianhenry/.wp-cli/packages/
WP-CLI cache dir:	/Users/brianhenry/.wp-cli/cache
WP-CLI global config:	
WP-CLI project config:	/Users/brianhenry/Sites/bh-wp-bitcoin-gateway/wp-cli.yml
WP-CLI version:	2.9.0

Provide a possible solution

I was already aware that it's inefficiently scanning – when improving that it should be easy to gracefully skip over broken symlinks too.

BrianHenryIE avatar Nov 26 '23 20:11 BrianHenryIE

Thanks for the report, @BrianHenryIE !

The broken symlink shouldn't be fatal for dist-ignore-command.

This seems like a reasonable fix.

danielbachhuber avatar Nov 27 '23 13:11 danielbachhuber

Is https://github.com/wp-cli/dist-archive-command/pull/91 a fix for this issue? If yes, should we close it? cc @danielbachhuber

thelovekesh avatar May 21 '24 11:05 thelovekesh