| 79 | static 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 | |
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; |
| 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. */ |
| 327 | static 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 | |
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)) |