Ticket #5872: mythtv-5872-allow_different_but_matching_zone_IDs.patch

File mythtv-5872-allow_different_but_matching_zone_IDs.patch, 6.3 KB (added by sphery <mtdean@…>, 15 years ago)
  • libs/libmyth/util.cpp

    old new  
    7676    return utc_offset;
    7777}
    7878
     79static bool compare_zone_files(QFileInfo first_file_info,
     80                               QFileInfo second_file_info)
     81{
     82    if (!first_file_info.isFile() || !second_file_info.isFile() ||
     83        !first_file_info.isReadable() || !second_file_info.isReadable())
     84        return false;
     85
     86    qint64 first_file_size = first_file_info.size();
     87    // sanity check - zoneinfo files should typically be less than
     88    // about 4kB, but leave room for growth
     89    if ((first_file_size > 200 * 1024) ||
     90        (second_file_info.size() != first_file_size))
     91        return false;
     92
     93    QFile first_file(first_file_info.absoluteFilePath());
     94    QByteArray first_file_data;
     95    first_file_data.resize(first_file_size);
     96    QFile second_file(second_file_info.absoluteFilePath());
     97    QByteArray second_file_data;
     98    second_file_data.resize(first_file_size);
     99    if (first_file.open(QIODevice::ReadOnly))
     100    {
     101        QDataStream in(&first_file);
     102        if (in.readRawData(first_file_data.data(),
     103                           first_file_size) != first_file_size)
     104        {
     105            first_file.close();
     106            return false;
     107        }
     108        first_file.close();
     109    }
     110    if (second_file.open(QIODevice::ReadOnly))
     111    {
     112        QDataStream in(&second_file);
     113        if (in.readRawData(second_file_data.data(),
     114                           first_file_size) != first_file_size)
     115        {
     116            second_file.close();
     117            return false;
     118        }
     119        second_file.close();
     120    }
     121    if (first_file_data == second_file_data)
     122        return true;
     123
     124    return false;
     125}
     126
    79127#ifndef USING_MINGW
    80128/* Helper function for getSystemTimeZoneID() that compares the
    81129   zoneinfo_file_path (regular) file with files in the zoneinfo_dir_path until
     
    89137    QFileInfoList dirlist = zoneinfo_dir.entryInfoList();
    90138    QFileInfo info;
    91139    QString basename;
    92     QFile zoneinfo_file(zoneinfo_file_path);
    93     qint64 zoneinfo_file_size = zoneinfo_file.size();
     140    QFileInfo zoneinfo_file_info(zoneinfo_file_path);
    94141
    95142    for (QFileInfoList::const_iterator it = dirlist.begin();
    96143         it != dirlist.end(); it++)
     
    109156            if (zone_id != "UNDEF")
    110157                return zone_id;
    111158        }
    112         else if (info.isFile() && (info.size() == zoneinfo_file_size) &&
    113                  info.isReadable())
     159        else if (compare_zone_files(zoneinfo_file_info, info))
    114160        {
    115             // sanity check - zoneinfo files should typically be less than
    116             // about 4kB, but leave room for growth
    117             if (zoneinfo_file_size > 200 * 1024)
    118                 continue;
    119             QFile this_file(info.absoluteFilePath());
    120             QByteArray zoneinfo_file_data;
    121             zoneinfo_file_data.resize(zoneinfo_file_size);
    122             QByteArray this_file_data;
    123             this_file_data.resize(zoneinfo_file_size);
    124             if (zoneinfo_file.open(QIODevice::ReadOnly))
    125             {
    126                 QDataStream in(&zoneinfo_file);
    127                 if (in.readRawData(zoneinfo_file_data.data(),
    128                                    zoneinfo_file_size) != zoneinfo_file_size)
    129                 {
    130                     zoneinfo_file.close();
    131                     return zone_id;
    132                 }
    133                 zoneinfo_file.close();
    134             }
    135             if (this_file.open(QIODevice::ReadOnly))
    136             {
    137                 QDataStream in(&this_file);
    138                 if (in.readRawData(this_file_data.data(),
    139                                    zoneinfo_file_size) != zoneinfo_file_size)
    140                 {
    141                     this_file.close();
    142                     return zone_id;
    143                 }
    144                 this_file.close();
    145             }
    146             if (zoneinfo_file_data == this_file_data)
    147             {
    148                 zone_id = info.absoluteFilePath();
    149                 break;
    150             }
     161            zone_id = info.absoluteFilePath();
     162            break;
    151163        }
    152164    }
    153165    return zone_id;
     
    309321    return zone_id;
    310322}
    311323
     324/* Helper function for checkTimeZone() that compares zone ID's.
     325   In the event that the zone ID's differ, checks to see if the local
     326   zoneinfo database has both zone ID's and if they're equivalent. */
     327static bool compare_zone_IDs(QString firstZoneID, QString secondZoneID)
     328{
     329    // Some distros use spaces rather than underscores in the zone ID, so
     330    // allow matches where the only difference is space vs. underscore.
     331    firstZoneID.replace(' ', '_');
     332    secondZoneID.replace(' ', '_');
     333    if (firstZoneID == secondZoneID)
     334        return true;
     335
     336    // Although the zone ID names don't match, they may refer to equivalent
     337    // rules, so compare the files
     338    QString zoneinfo_dir_path("/usr/share/zoneinfo");
     339    QFileInfo firstInfo(zoneinfo_dir_path + "/" + firstZoneID);
     340    QFileInfo secondInfo(zoneinfo_dir_path + "/" + secondZoneID);
     341    if (compare_zone_files(firstInfo, secondInfo))
     342        return true;
     343
     344    return false;
     345}
     346
    312347static void print_timezone_info(QString master_zone_id, QString local_zone_id,
    313348                                int master_utc_offset, int local_utc_offset,
    314349                                QString master_time, QString local_time)
     
    373408        have_zone_IDs = false;
    374409    }
    375410
    376     // Some distros use spaces rather than underscores in the zone ID, so
    377     // allow matches where the only difference is space vs. underscore.
    378     // Rather than modify the original zone ID's, modify a copy for the
    379     // comparison so the error message will show a difference in zone ID
    380     // as well as offset/current time in case the definitions differ.
    381     QString master_zone_compare = master_time_zone_ID;
    382     QString local_zone_compare = local_time_zone_ID;
    383     master_zone_compare.replace(' ', '_');
    384     local_zone_compare.replace(' ', '_');
    385     if (have_zone_IDs && (master_zone_compare != local_zone_compare))
     411    if (have_zone_IDs &&
     412        !compare_zone_IDs(master_time_zone_ID, local_time_zone_ID))
    386413    {
    387414        VERBOSE(VB_IMPORTANT, "Time zone settings on the master backend "
    388415                              "differ from those on this system.");