Skip to content

Commit

Permalink
system-timezone: do not accept timezone name if it's not in region/ci…
Browse files Browse the repository at this point in the history
…ty format

`plugins/datetime/system-timezone.c` finds timezone name out based on system timezone config - `/etc/localtime` file.
Upstream python code in `cinnamon-setting calendar` expects timezone name in `Region/City` format.
`/etc/localtime` file itself doesn't container this data.
To figure the name out plugins/datetime/system-timezone.c code is searching `SYSTEM_ZONEINFODIR` (/usr/share/zoneinfo) directory.
The timezone name is determined based on filename path with `SYSTEM_ZONEINFODIR` prefix cut.

there are miltiple instances of the same timezone file under different names and subfolders in the `SYSTEM_ZONEINFODIR` folder.
I. e a timezone may have several names, i. e. files in that folder.
For example, `/usr/share/zoneinfo/Navajo` and `/usr/share/zoneinfo/America/Denver` are the same timezones.

In some operating systems `/etc/localtime` is a symlink to `/usr/share/zoneinfo/Navajo` which is the symlink to `/usr/share/zoneinfo/America/Denver`.
In other operating systems those may be hardlinks.
In third operating systems those files might be just simple copies of each other.
Of course there might be a combination of all those scenarios.

The code in `plugins/datetime/system-timezone.c` does its best to determine timezone name by following links, comparing files content, etc.
It covers those different scenarios with sym-, hard- links, copied, etc describe above.

This patch is for the case when all timezone files are copies.
Currently `recursive_compare()` in `plugins/datetime/system-timezone.c` gives up when it finds first copy of `/etc/localtime` under `SYSTEM_ZONEINFODIR` folder.
Which is unfortunately `/usr/share/zoneinfo/Navajo` in my example, not `/usr/share/zoneinfo/America/Denver`.
So upstream python code in `cinnamon-setting calendar` gets timezone name as `Navajo`, while it is expecting rather `America/Denver`.

Fix it by checking if timezone name has slash "/" in its name.
If it doesn't then keep running `recursive_compare()` against `SYSTEM_ZONEINFODIR` (/usr/share/zoneinfo) directory.
  • Loading branch information
timp87 committed Oct 10, 2024
1 parent d97f923 commit 40fd504
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions plugins/datetime/system-timezone.c
Original file line number Diff line number Diff line change
Expand Up @@ -547,11 +547,19 @@ recursive_compare (struct stat *localtime_stat,
CompareFiles compare_func)
{
struct stat file_stat;
char *relpath = NULL;

if (g_stat (file, &file_stat) != 0)
return NULL;

if (S_ISREG (file_stat.st_mode)) {
relpath = system_timezone_strip_path_if_valid (file);
if (g_strstr_len (relpath, -1, "/") == NULL) {
g_free (relpath);
return NULL;
}
g_free (relpath);

if (compare_func (localtime_stat,
&file_stat,
localtime_content,
Expand Down

0 comments on commit 40fd504

Please sign in to comment.