protected function detectChangesOnPath($path, $filenamePattern)
    {
        $currentDirectoryChanged = false;
        try {
            $currentSubDirectoriesAndFiles = $this->readMonitoredDirectoryRecursively($path, $filenamePattern);
        } catch (\Exception $exception) {
            $currentSubDirectoriesAndFiles = [];
            $this->changedPaths[$path] = ChangeDetectionStrategyInterface::STATUS_DELETED;
        }

        $nowDetectedFilesAndDirectories = [];
        if (!isset($this->directoriesAndFiles[$path])) {
            $this->directoriesAndFiles[$path] = [];
            $this->changedPaths[$path] = ChangeDetectionStrategyInterface::STATUS_CREATED;
        }

        foreach ($currentSubDirectoriesAndFiles as $pathAndFilename) {
            $status = $this->changeDetectionStrategy->getFileStatus($pathAndFilename);
            if ($status !== ChangeDetectionStrategyInterface::STATUS_UNCHANGED) {
                $this->changedFiles[$pathAndFilename] = $status;
                $currentDirectoryChanged = true;
            }

            if (isset($this->directoriesAndFiles[$path][$pathAndFilename])) {
                unset($this->directoriesAndFiles[$path][$pathAndFilename]);
            }
            $nowDetectedFilesAndDirectories[$pathAndFilename] = 1;
        }

        if ($this->directoriesAndFiles[$path] !== []) {
            foreach (array_keys($this->directoriesAndFiles[$path]) as $pathAndFilename) {
                $this->changedFiles[$pathAndFilename] = ChangeDetectionStrategyInterface::STATUS_DELETED;
                if ($this->changeDetectionStrategy instanceof StrategyWithMarkDeletedInterface) {
                    $this->changeDetectionStrategy->setFileDeleted($pathAndFilename);
                } else {
                    // This call is needed to mark the file deleted in any possibly existing caches of the strategy.
                    // The return value is not important as we know this file doesn't exist so we set the status to DELETED anyway.
                    $this->changeDetectionStrategy->getFileStatus($pathAndFilename);
                }
            }
            $currentDirectoryChanged = true;
        }

        if ($currentDirectoryChanged) {
            $this->setDetectedFilesForPath($path, $nowDetectedFilesAndDirectories);
        }

        return $currentDirectoryChanged;
    }