bug-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] remap translator: remap prefixes instead of complete file names


From: Joan Lledó
Subject: [PATCH] remap translator: remap prefixes instead of complete file names
Date: Fri, 20 Dec 2019 19:59:29 +0100 (CET)

From: Joan Lledó <jlledom@member.fsf.org>

* trans/remap.c:
        * trivfs_S_dir_lookup():
                * Match and replace prefixes instead of complete
                  file names. This is needed to remap entire file
                  systems, not only trivial ones.
---
 trans/remap.c | 25 +++++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)

diff --git a/trans/remap.c b/trans/remap.c
index 5afbaa02..fcd276d6 100644
--- a/trans/remap.c
+++ b/trans/remap.c
@@ -65,21 +65,30 @@ trivfs_S_dir_lookup (struct trivfs_protid *diruser,
                     mach_msg_type_name_t *retry_port_type)
 {
   struct remap *remap;
+  string_t dest = { };
+  size_t prefix_size;
 
   if (!diruser)
     return EOPNOTSUPP;
 
   for (remap = remaps; remap; remap = remap->next)
-    /* FIXME: should match just prefix of filename too */
-    if (!strcmp (remap->from, filename))
-      {
+    {
+      prefix_size = strlen (remap->from);
+      if (!strncmp (remap->from, filename, prefix_size)
+         && (filename[prefix_size] == '\0' || filename[prefix_size] == '/'))
+       {
+         snprintf (dest, sizeof (dest), "%s%s", remap->to,
+                   filename + prefix_size);
+
 #ifdef DEBUG
-       fprintf (stderr,"replacing %s with %s\n", remap->from, remap->to);
-       fflush (stderr);
+         fprintf (stderr, "replacing %s with %s\n", filename, dest);
+         fflush (stderr);
 #endif
-       filename = remap->to;
-       break;
-      }
+
+         filename = dest;
+         break;
+       }
+    }
 
   *do_retry = FS_RETRY_REAUTH;
   *retry_port = getcrdir ();
-- 
2.20.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]