From: Kevin Day Date: Mon, 18 Jul 2022 03:36:55 +0000 (-0500) Subject: Bugfix: The copy operation doesn't work properly with trailing slashes. X-Git-Tag: 0.6.0~39 X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=e70631a5463f7dcb7ad70a0f92040c2d59ad947a;p=fll Bugfix: The copy operation doesn't work properly with trailing slashes. The generated path might not be valid when a trailing slash is supplied on the source or the destination. Increase the static array size to accommodate at least 2 added separators. Only add the separators if one does not already exist. This does not attempt to clean up the code if there are multiple separators beyond the first. (That is to say "copy a/// b///" will not become "copy a/ b/".) --- diff --git a/level_3/fake/c/private-make-operate_process_type.c b/level_3/fake/c/private-make-operate_process_type.c index f16818a..615001a 100644 --- a/level_3/fake/c/private-make-operate_process_type.c +++ b/level_3/fake/c/private-make-operate_process_type.c @@ -65,7 +65,7 @@ extern "C" { for (; i < total; ++i) { - destination.used = data_make->cache_arguments.array[total].used; + destination.used = data_make->cache_arguments.array[total].used + 1; if (existing) { destination.used += data_make->cache_arguments.array[i].used + 1; @@ -74,12 +74,47 @@ extern "C" { f_char_t destination_string[destination.used + 1]; destination.string = destination_string; destination_string[destination.used] = 0; + destination_string[destination.used - 1] = 0; + + if (existing) { + destination_string[destination.used - 2] = 0; + } memcpy(destination_string, data_make->cache_arguments.array[total].string, sizeof(f_char_t) * data_make->cache_arguments.array[total].used); if (existing) { - memcpy(destination_string + data_make->cache_arguments.array[total].used + 1, data_make->cache_arguments.array[i].string, sizeof(f_char_t) * data_make->cache_arguments.array[i].used); - destination_string[data_make->cache_arguments.array[total].used] = f_path_separator_s.string[0]; + if (destination_string[data_make->cache_arguments.array[total].used - 1] == f_path_separator_s.string[0]) { + memcpy(destination_string + data_make->cache_arguments.array[total].used, data_make->cache_arguments.array[i].string, sizeof(f_char_t) * data_make->cache_arguments.array[i].used); + + if (data_make->cache_arguments.array[i].string[data_make->cache_arguments.array[i].used - 1] == f_path_separator_s.string[0]) { + destination.used -= 2; + } + else { + destination_string[data_make->cache_arguments.array[total].used + data_make->cache_arguments.array[i].used] = f_path_separator_s.string[0]; + + --destination.used; + } + } + else { + memcpy(destination_string + data_make->cache_arguments.array[total].used + 1, data_make->cache_arguments.array[i].string, sizeof(f_char_t) * data_make->cache_arguments.array[i].used); + + destination_string[data_make->cache_arguments.array[total].used] = f_path_separator_s.string[0]; + + if (data_make->cache_arguments.array[i].string[data_make->cache_arguments.array[i].used - 1] == f_path_separator_s.string[0]) { + --destination.used; + } + else { + destination_string[data_make->cache_arguments.array[total].used + 1 + data_make->cache_arguments.array[i].used] = f_path_separator_s.string[0]; + } + } + } + else { + if (destination_string[data_make->cache_arguments.array[total].used - 1] == f_path_separator_s.string[0]) { + --destination.used; + } + else { + destination_string[data_make->cache_arguments.array[total].used] = f_path_separator_s.string[0]; + } } status_file = f_directory_is(data_make->cache_arguments.array[i]);