Skip to content

Commit

Permalink
Use --include before --exclude in rsync commands (#1304)
Browse files Browse the repository at this point in the history
  • Loading branch information
pjcdawkins authored Aug 21, 2023
1 parent 82f04b1 commit cf276c6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Command/Mount/MountDownloadCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ protected function configure()
->addOption('source-path', null, InputOption::VALUE_NONE, "Use the mount's source path (rather than the mount path) as a subdirectory of the target, when --all is used")
->addOption('delete', null, InputOption::VALUE_NONE, 'Whether to delete extraneous files in the target directory')
->addOption('exclude', null, InputOption::VALUE_IS_ARRAY|InputOption::VALUE_REQUIRED, 'File(s) to exclude from the download (pattern)')
->addOption('include', null, InputOption::VALUE_IS_ARRAY|InputOption::VALUE_REQUIRED, 'File(s) to include in the download (pattern)')
->addOption('include', null, InputOption::VALUE_IS_ARRAY|InputOption::VALUE_REQUIRED, 'File(s) not to exclude (pattern)')
->addOption('refresh', null, InputOption::VALUE_NONE, 'Whether to refresh the cache');
$this->addProjectOption();
$this->addEnvironmentOption();
Expand Down
2 changes: 1 addition & 1 deletion src/Command/Mount/MountUploadCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ protected function configure()
->addOption('mount', 'm', InputOption::VALUE_REQUIRED, 'The mount (as an app-relative path)')
->addOption('delete', null, InputOption::VALUE_NONE, 'Whether to delete extraneous files in the mount')
->addOption('exclude', null, InputOption::VALUE_IS_ARRAY|InputOption::VALUE_REQUIRED, 'File(s) to exclude from the upload (pattern)')
->addOption('include', null, InputOption::VALUE_IS_ARRAY|InputOption::VALUE_REQUIRED, 'File(s) to include in the upload (pattern)')
->addOption('include', null, InputOption::VALUE_IS_ARRAY|InputOption::VALUE_REQUIRED, 'File(s) not to exclude (pattern)')
->addOption('refresh', null, InputOption::VALUE_NONE, 'Whether to refresh the cache');
$this->addProjectOption();
$this->addEnvironmentOption();
Expand Down
12 changes: 11 additions & 1 deletion src/Service/Rsync.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,17 @@ private function doSync($from, $to, array $options = [])
if (!empty($options['delete'])) {
$params[] = '--delete';
}
foreach (['exclude', 'include'] as $option) {

// Add include and exclude rules.
//
// The --include option should be placed before --exclude. From the
// rsync manual:
// "The order of the rules is important because the first rule that
// matches is the one that takes effect. Thus, if an early rule
// excludes a file, no include rule that comes after it can have any
// effect. This means that you must place any include overrides
// somewhere prior to the exclude that it is intended to limit."
foreach (['include', 'exclude'] as $option) {
if (!empty($options[$option])) {
foreach ($options[$option] as $value) {
$params[] = '--' . $option . '=' . $value;
Expand Down

0 comments on commit cf276c6

Please sign in to comment.