/*!
    Convenience function that attempts to unlock the file with identifier \a id that was locked by \c QMail::fileLock.

    Returns \c true for success or \c false otherwise.

    \sa QMail::fileLock()
*/
bool QMail::fileUnlock(int id)
{
#ifdef Q_OS_WIN
    QMap<int, HANDLE>::iterator it = lockedFiles.find(id);
    if (it != lockedFiles.end()) {
        if (::UnlockFile(it.value(), 0, 0, 1, 0) == FALSE) {
            qWarning() << "Unable to unlock file:" << lastSystemErrorMessage();
        } else {
            if (::CloseHandle(it.value()) == FALSE) {
                qWarning() << "Unable to close handle:" << lastSystemErrorMessage();
            }

            lockedFiles.erase(it);
            return true;
        }
    }

    return false;
#else

    int result = -1;

    result = ::close(id);
    if (result == -1)
        return false;

    return true;
#endif
}
Пример #2
0
/*!
    Convenience function that attempts to unlock the file with identifier \a id that was locked by \c QMail::fileLock.

    Returns \c true for success or \c false otherwise.

    \sa QMail::fileLock()
*/
bool QMail::fileUnlock(int id)
{
#ifdef Q_OS_WIN
    QMap<int, HANDLE>::iterator it = lockedFiles.find(id);
    if (it != lockedFiles.end()) {
        if (::UnlockFile(it.value(), 0, 0, 1, 0) == FALSE) {
            qWarning() << "Unable to unlock file:" << lastSystemErrorMessage();
        } else {
            if (::CloseHandle(it.value()) == FALSE) {
                qWarning() << "Unable to close handle:" << lastSystemErrorMessage();
            }

            lockedFiles.erase(it);
            return true;
        }
    }

    return false;
#else
    struct flock fl;

    fl.l_type = F_UNLCK;
    fl.l_whence = SEEK_SET;
    fl.l_start = 0;
    fl.l_len = 0;

    int result = -1;

    if((result = ::fcntl(id,F_SETLK, &fl)) == -1)
        return false;

    if((result = ::close(id)) == -1)
        return false;

    return true;
#endif
}