From 172ba6811cc1bc0cb87c7a0e03abf88f80321464 Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Fri, 28 May 2021 23:06:16 +0200 Subject: [PATCH] Fix paths During a check, paths should be relative to the input file During normal operation paths are relative to CWD unless they are absolute --- src/sums.d | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/sums.d b/src/sums.d index 2a0b84c..d64d29e 100644 --- a/src/sums.d +++ b/src/sums.d @@ -24,6 +24,7 @@ import tiger; import std.exception; import std.format; import std.array : appender; +import std.path; private void writeError (string parFile, string parMessage) { stderr.writefln("tigersum: %s: %s", parFile, parMessage); @@ -37,7 +38,7 @@ void calculateSums (in string[] parFiles, in string parCWD, bool parTiger2, stri ulong[] read_buff = new ulong[READ_BUFF_BLOCKS * 64 / ulong.sizeof]; foreach (file_name; parFiles) { - const auto curr_path = parCWD ~ file_name; + const auto curr_path = buildPath(parCWD, file_name); File curr_file; try { curr_file = File(curr_path, parFileMode); @@ -62,7 +63,7 @@ void calculateSums (in string[] parFiles, in string parCWD, bool parTiger2, stri } } -bool checkSums (in string parFile, in string parCWD, bool parTiger2, string parFileMode) { +bool checkSums (in string parFile, in string parRoot, bool parTiger2, string parFileMode) { File curr_list = File(parFile, "r"); bool ret_val = true; const auto reg_bsd = r"^tiger \((.+)\)\s*=\s*([a-fA-F0-9]{48})$"; @@ -88,7 +89,7 @@ bool checkSums (in string parFile, in string parCWD, bool parTiger2, string parF const string capt_filename = cast(string)m.captures[index_file]; writef("%s: ", capt_filename); - const string curr_path = parCWD ~ capt_filename; + const string curr_path = buildPath(parRoot, capt_filename); File curr_file; try { curr_file = File(curr_path, parFileMode); @@ -135,8 +136,8 @@ bool checkSums (in string parFile, in string parCWD, bool parTiger2, string parF bool checkSums (in string[] parFiles, in string parCWD, bool parTiger2, string parFileMode) { bool ret_val = true; foreach (file_name; parFiles) { - const auto curr_path = parCWD ~ file_name; - ret_val &= checkSums(curr_path, parCWD, parTiger2, parFileMode); + string curr_path = buildPath(parCWD, file_name); + ret_val &= checkSums(curr_path, dirName(curr_path), parTiger2, parFileMode); } return ret_val; }