Skip to content

[6.x] Fix deleting directories with a dot in their name - #16164

Merged
jasonvarga merged 1 commit into
statamic:6.xfrom
wake-up-jelle:fix/flysystem-directories-with-dots
Dec 4, 2026
Merged

jasonvarga merged 1 commit into
statamic:6.xfrom
wake-up-jelle:fix/flysystem-directories-with-dots

Conversation

@wake-up-jelle

Copy link
Copy Markdown
Contributor

FlysystemAdapter inherits AbstractAdapter::isDirectory(), which decides whether a path is a directory by checking that it exists and has no extension. A directory with a dot in its name is therefore treated as a file.

This shows up with Forms 2 uploads. Temporary uploads are stored in statamic/form-uploads/{submission id}/{field}/, and submission ids contain a dot (e.g. 1765432100.1234). After a submission the temporary files are deleted, leaving the empty folders behind. When DeleteTemporaryFileUploads later runs deleteEmptySubfolders(), delete() calls isDirectory(), gets false and calls unlink() on the directory:

League\Flysystem\UnableToDeleteFile: Unable to delete file located at: .../storage/app/statamic/form-uploads/1765432100.1234. unlink(...): Is a directory

The middleware runs before the request is handled, so the Control Panel request that wins the cleanup lottery fails with a 500 (on disks with throw enabled; otherwise the folders are silently never cleaned up).

This PR overrides isDirectory() in FlysystemAdapter to ask the filesystem via directoryExists(), matching what FilesystemAdapter already does with Filesystem::isDirectory(). This also stops files without an extension (e.g. LICENSE) being treated as directories.

Tests are added to the shared FilesystemAdapterTests, so they run against both adapters. Both fail for FlysystemAdapter without the fix.

To reproduce manually:

Storage::disk('local')->makeDirectory('test/1765432100.1234/image');
File::disk('local')->deleteEmptySubfolders('test');

…extension

FlysystemAdapter inherited AbstractAdapter::isDirectory(), which treats any
path with an extension as a file. Directories with a dot in their name
(e.g. form submission ids like 1765432100.1234) were therefore deleted with
unlink(), which fails with "Is a directory".
@jasonvarga
jasonvarga merged commit e38d93a into statamic:6.x Dec 4, 2026
61 checks passed
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.

2 participants