]> Kevux Git Server - fll/commitdiff
Bugfix: The copy operation doesn't work properly with trailing slashes.
authorKevin Day <thekevinday@gmail.com>
Mon, 18 Jul 2022 03:36:55 +0000 (22:36 -0500)
committerKevin Day <thekevinday@gmail.com>
Mon, 18 Jul 2022 03:36:55 +0000 (22:36 -0500)
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/".)

level_3/fake/c/private-make-operate_process_type.c

index f16818a3ac759546132d4aeb9038c28a0a05befc..615001affc8b0a2f97b50abdaa75562392528a05 100644 (file)
@@ -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]);