From 7842db96a650deca6a4f1e05d74b0fdea47ca2cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Ferreira?= Date: Mon, 26 Oct 2020 18:13:50 +0000 Subject: [PATCH] timezone: wrap dirEntries foreach in a trusted lambda instead of making the whole function @trusted MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Luís Ferreira --- std/datetime/timezone.d | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/std/datetime/timezone.d b/std/datetime/timezone.d index 063052914..83771d4fd 100644 --- a/std/datetime/timezone.d +++ b/std/datetime/timezone.d @@ -2417,7 +2417,7 @@ public: Throws: `FileException` if it fails to read from disk. +/ - static string[] getInstalledTZNames(string subName = "", string tzDatabaseDir = defaultTZDatabaseDir) @trusted + static string[] getInstalledTZNames(string subName = "", string tzDatabaseDir = defaultTZDatabaseDir) @safe { import std.algorithm.sorting : sort; import std.array : appender; @@ -2448,23 +2448,28 @@ public: else { import std.path : baseName; - foreach (DirEntry de; dirEntries(tzDatabaseDir, SpanMode.depth)) - { - if (de.isFile) + // dirEntries is @system because it uses a DirIterator with a + // RefCounted variable, but here, no references to the payload is + // escaped to the outside, so this should be @trusted + () @trusted { + foreach (DirEntry de; dirEntries(tzDatabaseDir, SpanMode.depth)) { - auto tzName = de.name[tzDatabaseDir.length .. $]; - - if (!tzName.extension().empty || - !tzName.startsWith(subName) || - baseName(tzName) == "leapseconds" || - tzName == "+VERSION") + if (de.isFile) { - continue; - } + auto tzName = de.name[tzDatabaseDir.length .. $]; - timezones.put(tzName); + if (!tzName.extension().empty || + !tzName.startsWith(subName) || + baseName(tzName) == "leapseconds" || + tzName == "+VERSION") + { + continue; + } + + timezones.put(tzName); + } } - } + }(); } sort(timezones.data);