private function getFolderNode($path, $create = false)
    {
        $location = $this->applyPathPrefix($path);
        if (!$create && !$this->session->nodeExists($location)) {
            // trigger the phpcr exception rather than trying to create parent nodes.
            return $this->session->getNode($location);
        }

        $folders = array();
        while (!$this->session->nodeExists($location)) {
            $folders[] = PathHelper::getNodeName($location);
            $location = PathHelper::getParentPath($location);
        }

        $node = $this->session->getNode($location);
        while (null !== $folder = array_pop($folders)) {
            $node = $node->addNode($folder, 'nt:folder');
        }
        if (!$node->isNodeType('nt:folder')) {
            throw new \LogicException($path.' is not a folder but '.$node->getPrimaryNodeType()->getName());
        }

        if ($create) {
            $this->session->save();
        }

        return $node;
    }