protected function openLockHandle()
    {
        // PHP allows periods, '.', to be scheme names. Normalize the scheme
        // name to something that won't cause problems. Also, avoid problems
        // with case-insensitive filesystems. We use bin2hex() rather than a
        // hashing function since most scheme names are small, and bin2hex()
        // only doubles the string length.
        $sub_dir = bin2hex($this->getProtocol());

        // Since we're flattening out whole filesystems, at least create a
        // sub-directory for each scheme to attempt to reduce the number of
        // files per directory.
        $temp_dir = sys_get_temp_dir() . '/flysystem-stream-wrapper/' . $sub_dir;

        // Race free directory creation. If @mkdir() fails, fopen() will fail
        // later, so there's no reason to test again.
        ! is_dir($temp_dir) && @mkdir($temp_dir, 0777, true);

        // Normalize paths so that locks are consistent.
        // We are using sha1() to avoid the file name limits, and case
        // insensitivity on Windows. This is not security sensitive.
        $lock_key = sha1(Util::normalizePath($this->getTarget()));

        // Relay the lock to a real filesystem lock.
        return fopen($temp_dir . '/' . $lock_key, 'c');
    }