Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions features/distignore.feature
Original file line number Diff line number Diff line change
Expand Up @@ -385,3 +385,23 @@ Feature: Generate a distribution archive of a project
| targz | tar.gz | tar -zxvf | foo |
| zip | zip | unzip | bar7 |
| targz | tar.gz | tar -zxvf | bar8 |

Scenario: Does not crash when a broken symlink is encountered
# @see https://github.com/wp-cli/dist-archive-command/issues/86
Given an empty directory
And an empty foo/target-directory directory
And a foo/.distignore file:
"""
"""

When I run `ln -s {RUN_DIR}/foo/target-directory {RUN_DIR}/foo/symlink`
Then STDERR should be empty

When I run `rm -rf {RUN_DIR}/foo/target-directory`
Then STDERR should be empty

When I try `wp dist-archive foo`
Then STDERR should contain:
"""
Error: Broken symlink at /symlink. Target missing at
"""
16 changes: 12 additions & 4 deletions src/Dist_Archive_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -484,10 +484,18 @@ private function get_file_list( $source_dir_path, $excluded = false ) {
*/
foreach ( $iterator as $item ) {
$relative_filepath = str_replace( $source_dir_path, '', $item->getPathname() );
if ( $this->checker->isPathIgnored( $relative_filepath ) ) {
$excluded_files[] = $relative_filepath;
} else {
$included_files[] = $relative_filepath;
try {
if ( $this->checker->isPathIgnored( $relative_filepath ) ) {
$excluded_files[] = $relative_filepath;
} else {
$included_files[] = $relative_filepath;
}
} catch ( \Inmarelibero\GitIgnoreChecker\Exception\InvalidArgumentException $exception ) {
if ( $item->isLink() && ! file_exists( readlink( $item->getPathname() ) ) ) {
WP_CLI::error( "Broken symlink at {$relative_filepath}. Target missing at {$item->getLinkTarget()}." );
} else {
WP_CLI::error( $exception->getMessage() );
}
}
}

Expand Down