Skip to content

Commit eea3bd3

Browse files
authored
[libc++][TZDB] Fixes relative path resolving. (#87882)
The path /etc/localtime is a symlink. This symlink can be a relative path. This fixes resolving a relative symlink. Since the path used is hard-coded based on the user's system there is no good way to test this. Fixes: #87872
1 parent 1381645 commit eea3bd3

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

libcxx/src/tzdb.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -717,8 +717,12 @@ void __init_tzdb(tzdb& __tzdb, __tz::__rules_storage_type& __rules) {
717717
std::__throw_runtime_error("tzdb: the path '/etc/localtime' is not a symlink");
718718

719719
filesystem::path __tz = filesystem::read_symlink(__path);
720-
string __name = filesystem::relative(__tz, "/usr/share/zoneinfo/");
720+
// The path may be a relative path, in that case convert it to an absolute
721+
// path based on the proper initial directory.
722+
if (__tz.is_relative())
723+
__tz = filesystem::canonical("/etc" / __tz);
721724

725+
string __name = filesystem::relative(__tz, "/usr/share/zoneinfo/");
722726
if (const time_zone* __result = tzdb.__locate_zone(__name))
723727
return __result;
724728

0 commit comments

Comments
 (0)