<commit_before>#include "deviceinfo.h"
#include "log/logger.h"

#include <QCryptographicHash>
#include <QDir>
#include <fstab.h>
#include <unistd.h>
#include <QThread>
#include <QNetworkConfigurationManager>

LOGGER(DeviceInfo);

namespace
{
    static const char* FSEntries[] =
    {
        "/",
        "/boot",
        NULL
    };
}

DeviceInfo::DeviceInfo()
: d(NULL)
{
}

DeviceInfo::~DeviceInfo()
{
}

QString DeviceInfo::deviceId() const
{
    if (int ret = setfsent() != 1)
    {
        LOG_ERROR(QString("Error opening fstab: setfsent returned %1").arg(ret));
        return QString();
    }

    QByteArray uuid;

    for (const char** fsentry=FSEntries; *fsentry != NULL; ++fsentry)
    {
        fstab* tab = getfsfile(*fsentry);
        if (!tab)
        {
            continue;
        }

        uuid = QByteArray::fromRawData(tab->fs_spec, strlen(tab->fs_spec));

        if (uuid.indexOf("UUID=") == 0)
        {
            uuid.remove(0, 5);
            break;
        }
        else
        {
            // No UUID in fstab
            QFileInfo info(uuid);
            uuid.clear();
            QString target;

            if ( info.isSymLink() )
            {
                target = info.symLinkTarget();
            }
            else
            {
                target = info.absoluteFilePath();
            }

            QDir byUuidDir("/dev/disk/by-uuid");
            foreach(const QFileInfo& uuidFileInfo, byUuidDir.entryInfoList(QDir::Files))
            {
                if (target == uuidFileInfo.symLinkTarget())
                {
                    uuid = uuidFileInfo.fileName().toUtf8();
                    break;
                }
            }

            if (!uuid.isEmpty())
            {
                break;
            }
        }
    }

    endfsent();

    if (uuid.isEmpty())
    {
        LOG_ERROR("No HDD UID found!");
        return QString();
    }

    LOG_INFO(QString("HDD UUID: %1").arg(QString::fromLatin1(uuid)));

    QCryptographicHash hash(QCryptographicHash::Sha224);
    hash.addData(uuid);

    return QString::fromLatin1(hash.result().toHex());
}<commit_msg>Also check for LABEL= in fstab<commit_after>#include "deviceinfo.h"
#include "log/logger.h"

#include <QCryptographicHash>
#include <QDir>
#include <fstab.h>
#include <unistd.h>
#include <QThread>
#include <QNetworkConfigurationManager>

LOGGER(DeviceInfo);

namespace
{
    static const char* FSEntries[] =
    {
        "/",
        "/boot",
        NULL
    };

    QByteArray uuidForDevice(const QString& device)
    {
        QByteArray uuid;

        QDir byUuidDir("/dev/disk/by-uuid");
        foreach(const QFileInfo& uuidFileInfo, byUuidDir.entryInfoList(QDir::Files))
        {
            if (device == uuidFileInfo.symLinkTarget())
            {
                uuid = uuidFileInfo.fileName().toUtf8();
                break;
            }
        }

        return uuid;
    }
}

DeviceInfo::DeviceInfo()
: d(NULL)
{
}

DeviceInfo::~DeviceInfo()
{
}

QString DeviceInfo::deviceId() const
{
    if (int ret = setfsent() != 1)
    {
        LOG_ERROR(QString("Error opening fstab: setfsent returned %1").arg(ret));
        return QString();
    }

    QByteArray uuid;

    for (const char** fsentry=FSEntries; *fsentry != NULL; ++fsentry)
    {
        fstab* tab = getfsfile(*fsentry);
        if (!tab)
        {
            continue;
        }

        uuid = QByteArray::fromRawData(tab->fs_spec, strlen(tab->fs_spec));

        if (uuid.indexOf("UUID=") == 0)
        {
            uuid.remove(0, 5);
            break;
        }
        else
        {
            // No UUID in fstab
            QString target;
            QFileInfo info;

            if (uuid.indexOf("LABEL=") == 0)
            {
                uuid.remove(0, 6);
                info = QFileInfo(QString("/dev/disk/by-label/%1").arg(QString::fromUtf8(uuid)));
            }
            else
            {
                info = QFileInfo(uuid);
            }

            uuid.clear();

            if ( info.isSymLink() )
            {
                target = info.symLinkTarget();
            }
            else
            {
                target = info.absoluteFilePath();
            }

            uuid = uuidForDevice(target);

            if (!uuid.isEmpty())
            {
                break;
            }
        }
    }

    endfsent();

    if (uuid.isEmpty())
    {
        LOG_ERROR("No HDD UID found!");
        return QString();
    }

    LOG_INFO(QString("HDD UUID: %1").arg(QString::fromLatin1(uuid)));

    QCryptographicHash hash(QCryptographicHash::Sha224);
    hash.addData(uuid);

    return QString::fromLatin1(hash.result().toHex());
}
{'fraction_non_alphanumeric': 0.13463996591393268, 'fraction_numerical': 0.006178099701746911, 'mean_word_length': 1.6332024677509815, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4648993', 'n_tokens_mistral': 1497, 'n_tokens_neox': 1440, 'n_words': 257}