Skip to content

Add Filesystem::directoryIsEmpty() to check for directory contents without listing them - #1939

Open
IonBazan wants to merge 1 commit into
thephpleague:3.xfrom
IonBazan:add-directory-is-empty
Open

IonBazan wants to merge 1 commit into
thephpleague:3.xfrom
IonBazan:add-directory-is-empty

Conversation

@IonBazan

Copy link
Copy Markdown

This adds directoryIsEmpty() to Filesystem and MountManager so callers can check whether a directory has contents without listing all of it.

It reads the first item of a shallow listContents() and stops there. Listings are lazy, so the rest of the directory is never read. A directory that does not exist counts as empty, which matches what listContents() returns for a missing path.

The method is on the concrete classes only. Adding it to FilesystemReader, FilesystemOperator or FilesystemAdapter would break third-party implementations in 3.x.

Closes #1870

This branch has not been deployed

No deployments
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.

Filesystem::isEmpty() method to check if a directory is empty without having to actually get the contents.

1 participant