Skip to content

fix: archive a whole directory without a pattern - #912

Merged
blaipr merged 1 commit into
mainfrom
fix/compressing-a-whole-directory-does-not-need-a-regex
Sep 7, 2026
Merged

fix: archive a whole directory without a pattern#912
blaipr merged 1 commit into
mainfrom
fix/compressing-a-whole-directory-does-not-need-a-regex

Conversation

@blaipr

@blaipr blaipr commented Sep 7, 2026

Copy link
Copy Markdown
Member

ArchiveHandler::compressDirectory(string $directory, ?string $regex = null) offers "archive the
whole directory" as an option, and taking it handed the null straight to
PharData::buildFromDirectory(), whose second parameter is declared string.

On PHP 8.5 that is a deprecation, on PHP 9 it is a fatal, and under this suite's error handler it is
already a hard error — which is how it surfaced, while writing the tests for #903. The one
production caller (BackupFile::backupApp()) always passes BACKUP_INCLUDE_REGEX, so nothing had
reached it.

The one-argument form is what "no pattern" means to Phar, so the argument is passed only when there
is one.

Correcting the record

#903's description called this a TypeError on the strength of the test-suite failure. It is a
deprecation notice in ordinary use — the archive is still built, with the null read as an empty
pattern. The consequence is a PHP 9 upgrade turning it into a fatal, not a break today. The rest of
that PR is unaffected.

While measuring this I also checked what Phar does with each spelling, because the answer decides
the fix: with the archive re-opened, buildFromDirectory($dir), …($dir, '') and …($dir, '/.*/')
all archive everything, and a narrower pattern filters as expected. An earlier reading of "the
one-argument form archives nothing" was an artefact of counting entries before the archive was
closed.

Test

aDirectoryCanBeArchivedWithNoPatternAtAll asserts the contents rather than the absence of an
error — the point is that the option still archives everything. It fails against the old call.

ArchiveHandler::compressDirectory(string $directory, ?string $regex = null) offers
'archive the whole directory' as an option, and taking it handed the null straight to
PharData::buildFromDirectory(), whose second parameter is declared string. That is a
deprecation on PHP 8.5, a fatal on PHP 9, and already a hard error under the test suite's
error handler — which is how it surfaced. The one production caller always passes
BACKUP_INCLUDE_REGEX, so nothing had reached it.

The one-argument form is what 'no pattern' means to Phar, so the argument is passed only
when there is one.

Corrects #903's description, which called this a TypeError on the strength of the
test-suite failure: in ordinary use it is a deprecation and the archive is still built.
@blaipr
blaipr merged commit 537d31a into main Sep 7, 2026
8 checks passed
@blaipr
blaipr deleted the fix/compressing-a-whole-directory-does-not-need-a-regex branch September 7, 2026 21:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant