]> git.seodisparate.com - SimpleArchiver/commitdiff
WIP remapping, verbose user/group mapping errors
authorStephen Seo <seo.disparate@gmail.com>
Mon, 6 Jan 2025 06:40:09 +0000 (15:40 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Mon, 6 Jan 2025 06:40:30 +0000 (15:40 +0900)
src/parser.c

index 9b387532cb8f5d352f43dc4d4ca636e3eb8b5aad..8a69cbb0b883cb147b76d8068eaa14ac9a988f77 100644 (file)
@@ -1079,11 +1079,28 @@ int simple_archiver_handle_map_user_or_group(
   }
 
   if (first_is_numeric && last_is_numeric) {
-    if (simple_archiver_hash_map_get(IDToID, first_id, sizeof(uint32_t))
-        || simple_archiver_hash_map_get(IDToName, first_id, sizeof(uint32_t))) {
+    uint32_t *mapped_id = simple_archiver_hash_map_get(IDToID,
+                                                       first_id,
+                                                       sizeof(uint32_t));
+    if (mapped_id) {
       fprintf(stderr,
               "ERROR: Mapping with key \"%" PRIu32 "\" already exists!\n",
               *first_id);
+      fprintf(stderr,
+              "  Already mapped to ID \"%" PRIu32 "\".\n",
+              *mapped_id);
+      return 1;
+    }
+    const char *mapped_name = simple_archiver_hash_map_get(IDToName,
+                                                           first_id,
+                                                           sizeof(uint32_t));
+    if (mapped_name) {
+      fprintf(stderr,
+              "ERROR: Mapping with key \"%" PRIu32 "\" already exists!\n",
+              *first_id);
+      fprintf(stderr,
+              "  Already mapped to name \"%s\".\n",
+              mapped_name);
       return 1;
     }
     if (simple_archiver_hash_map_insert(IDToID,
@@ -1104,11 +1121,28 @@ int simple_archiver_handle_map_user_or_group(
     last_id = NULL;
     first_id = NULL;
   } else if (first_is_numeric) {
-    if (simple_archiver_hash_map_get(IDToName, first_id, sizeof(uint32_t))
-        || simple_archiver_hash_map_get(IDToID, first_id, sizeof(uint32_t))) {
+    uint32_t *mapped_id = simple_archiver_hash_map_get(IDToID,
+                                                       first_id,
+                                                       sizeof(uint32_t));
+    if (mapped_id) {
       fprintf(stderr,
               "ERROR: Mapping with key \"%" PRIu32 "\" already exists!\n",
               *first_id);
+      fprintf(stderr,
+              "  Already mapped to ID \"%" PRIu32 "\".\n",
+              *mapped_id);
+      return 1;
+    }
+    const char *mapped_name = simple_archiver_hash_map_get(IDToName,
+                                                           first_id,
+                                                           sizeof(uint32_t));
+    if (mapped_name) {
+      fprintf(stderr,
+              "ERROR: Mapping with key \"%" PRIu32 "\" already exists!\n",
+              *first_id);
+      fprintf(stderr,
+              "  Already mapped to name \"%s\".\n",
+              mapped_name);
       return 1;
     }
     if (simple_archiver_hash_map_insert(IDToName,
@@ -1129,15 +1163,29 @@ int simple_archiver_handle_map_user_or_group(
     last_buf = NULL;
     first_id = NULL;
   } else if (last_is_numeric) {
-    if (simple_archiver_hash_map_get(NameToID,
-                                     first_buf,
-                                     strlen(first_buf) + 1)
-        || simple_archiver_hash_map_get(NameToName,
-                                        first_buf,
-                                        strlen(first_buf) + 1)) {
+    uint32_t *mapped_id = simple_archiver_hash_map_get(NameToID,
+                                                       first_buf,
+                                                       strlen(first_buf) + 1);
+    if (mapped_id) {
       fprintf(stderr,
               "ERROR: Mapping with key \"%s\" already exists!\n",
-            first_buf);
+              first_buf);
+      fprintf(stderr,
+              "  Already mapped to ID \"%" PRIu32 "\".\n",
+              *mapped_id);
+      return 1;
+    }
+    const char *mapped_name = simple_archiver_hash_map_get(NameToName,
+                                                           first_buf,
+                                                           strlen(first_buf)
+                                                             + 1);
+    if (mapped_name) {
+      fprintf(stderr,
+              "ERROR: Mapping with key \"%s\" already exists!\n",
+              first_buf);
+      fprintf(stderr,
+              "  Already mapped to name \"%s\".\n",
+              mapped_name);
       return 1;
     }
     if (simple_archiver_hash_map_insert(NameToID,
@@ -1158,15 +1206,29 @@ int simple_archiver_handle_map_user_or_group(
     last_id = NULL;
     first_buf = NULL;
   } else {
-    if (simple_archiver_hash_map_get(NameToName,
-                                     first_buf,
-                                     strlen(first_buf) + 1)
-        || simple_archiver_hash_map_get(NameToID,
-                                        first_buf,
-                                        strlen(first_buf) + 1)) {
+    uint32_t *mapped_id = simple_archiver_hash_map_get(NameToID,
+                                                       first_buf,
+                                                       strlen(first_buf) + 1);
+    if (mapped_id) {
       fprintf(stderr,
               "ERROR: Mapping with key \"%s\" already exists!\n",
-            first_buf);
+              first_buf);
+      fprintf(stderr,
+              "  Already mapped to ID \"%" PRIu32 "\".\n",
+              *mapped_id);
+      return 1;
+    }
+    const char *mapped_name = simple_archiver_hash_map_get(NameToName,
+                                                           first_buf,
+                                                           strlen(first_buf)
+                                                             + 1);
+    if (mapped_name) {
+      fprintf(stderr,
+              "ERROR: Mapping with key \"%s\" already exists!\n",
+              first_buf);
+      fprintf(stderr,
+              "  Already mapped to name \"%s\".\n",
+              mapped_name);
       return 1;
     }
     if (simple_archiver_hash_map_insert(NameToName,