From 8a276e9db6a4865c28b3bded45ebec2f7e0fb03b Mon Sep 17 00:00:00 2001 From: Fake Fake Date: Fri, 13 Dec 2024 14:48:16 -0500 Subject: [PATCH] Only include .distignore if .distfiles is absent --- src/Commands/Package.php | 92 ++++++++++++++++++++++++++++------------ 1 file changed, 66 insertions(+), 26 deletions(-) diff --git a/src/Commands/Package.php b/src/Commands/Package.php index 0e0f052..d01ecb4 100644 --- a/src/Commands/Package.php +++ b/src/Commands/Package.php @@ -201,6 +201,22 @@ protected function createZip( string $dir_to_zip, string $zip_filename, string $ return 0; } + /** + * Get the default things to exclude from sync. + * + * @return array + */ + public function getDefaultIgnoreLines(): array { + $working_dir = App::getConfig()->getWorkingDir(); + $zip_dir = str_replace( $working_dir, '', App::getConfig()->getZipDir() ); + + return [ + '.puprc', + '.pup-*', + $zip_dir, + ]; + } + /** * Get the files to exclude from sync. * @@ -230,33 +246,54 @@ public function getIgnoreLines( string $source ): array { } /** - * Get the files to include in sync. + * Get the distfiles lines to include in sync. * * @param string $source * * @return array */ - public function getIncludeLines( string $source ): array { - $include = []; - $include_files = [ - '.pup-distinclude', - '.pup-distfiles', - ]; + public function getDistfilesLines( string $source ): array { + $include = []; + $include_file = '.pup-distfiles'; - foreach ( $include_files as $include_file ) { - if ( ! file_exists( $source . $include_file ) ) { - continue; - } + if ( ! file_exists( $source . $include_file ) ) { + return []; + } - $lines = file( $source . $include_file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES ); + $lines = file( $source . $include_file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES ); - if ( ! $lines ) { - continue; - } + if ( ! $lines ) { + return []; + } + + $include = array_merge( $include, $lines ); - $include = array_merge( $include, $lines ); + return $include; + } + + /** + * Get the distinclude lines to include in sync. + * + * @param string $source + * + * @return array + */ + public function getDistincludeLines( string $source ): array { + $include = []; + $include_file = '.pup-include'; + + if ( ! file_exists( $source . $include_file ) ) { + return []; + } + + $lines = file( $source . $include_file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES ); + + if ( ! $lines ) { + return []; } + $include = array_merge( $include, $lines ); + return $include; } @@ -392,8 +429,17 @@ protected function syncFiles( string $root, string $destination ): int { $this->buildSyncFiles( $source ); - $include = $this->getIncludeLines( $source ); - $ignore = $this->getIgnoreLines( $source ); + $distfiles = $this->getDistfilesLines( $source ); + $distinclude = $this->getDistincludeLines( $source ); + $include = array_merge( $distfiles, $distinclude ); + + $ignore = $this->getDefaultIgnoreLines(); + + // We only observe .distignore if there is no .distfiles files. + if ( empty( $distfiles ) ) { + $ignore = array_merge( $ignore, $this->getIgnoreLines( $source ) ); + } + $results = $this->migrateNegatedLines( $include, $ignore ); $include = $results['include']; $ignore = $results['ignore']; @@ -406,17 +452,11 @@ protected function syncFiles( string $root, string $destination ): int { foreach ( $iterator as $item ) { $path = ltrim( $iterator->getSubPathName(), '/\\' ); - if ( strpos( $path, '.pup' ) !== false ) { - continue; - } - - $is_included_file = $this->isIncludedFile( $path, $include ); - - if ( ! $is_included_file ) { + if ( ! $this->isIncludedFile( $path, $include ) ) { continue; } - if ( ! $is_included_file && $this->isIgnoredFile( $path, $ignore ) ) { + if ( $this->isIgnoredFile( $path, $ignore ) ) { continue; }