Skip to content

Commit

Permalink
Only include .distignore if .distfiles is absent
Browse files Browse the repository at this point in the history
  • Loading branch information
Fake Fake committed Dec 13, 2024
1 parent 282a9d1 commit 8a276e9
Showing 1 changed file with 66 additions and 26 deletions.
92 changes: 66 additions & 26 deletions src/Commands/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<int, string>
*/
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.
*
Expand Down Expand Up @@ -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<int, string>
*/
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<int, string>
*/
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;
}

Expand Down Expand Up @@ -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'];
Expand All @@ -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;
}

Expand Down

0 comments on commit 8a276e9

Please sign in to comment.