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

2019-12-22 Thread Samuel Thibault
Hello,

Joan Lledó via Bug reports for the GNU Hurd, le ven. 20 déc. 2019 19:59:29 
+0100, a ecrit:
> From: Joan Lledó 
> 
> * 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.

This looks good, applied, thanks!

> ---
>  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
> 
> 

-- 
Samuel
 muhahaha...
 ya un train qui part de Perrache à 14h57
 qui passe à Part-Dieu à 15h10
 si je le prends à Perrache, je suis en zone bleue
 si je le prends à Part-Dieu, je suis en zone blanche
 donc je vais le prendre à Perrache *mais* à Part-Dieu ;-)
 -+- #ens-mim - vive la SNCF -+-



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

2019-12-20 Thread Joan Lledó via Bug reports for the GNU Hurd
From: Joan Lledó 

* 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




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

2019-12-15 Thread Samuel Thibault
Joan Lledó via Bug reports for the GNU Hurd, le dim. 15 déc. 2019 19:57:43 
+0100, a ecrit:
> diff --git a/trans/remap.c b/trans/remap.c
> index 5afbaa02..e3d5fa0a 100644
> --- a/trans/remap.c
> +++ b/trans/remap.c
> @@ -65,19 +65,23 @@ trivfs_S_dir_lookup (struct trivfs_protid *diruser,
>mach_msg_type_name_t *retry_port_type)
>  {
>struct remap *remap;
> +  char dest[NAME_MAX] = { };

Rather use string_t, which is the actual type of retry_name.

> -if (!strcmp (remap->from, filename))
> +if (!strncmp (remap->from, filename, strlen (remap->from)))

You need to avoid the case when filename happens to begin like
remap->from, e.g. remap has a /foo -> /bar translation, and the entry to
be translated is /foo2, we don't want to remap in that case. The matched
part thus have to be followed by either \0 or '/', otherwise it's not a
match.

> + snprintf (dest, NAME_MAX, "%s%s", remap->to,

Rather use sizeof() here.

> +   filename + strlen (remap->from));

Compute strlen(remap->from) only once.

> - filename = remap->to;
> +
> + strncpy (filename, dest, NAME_MAX);

No, you shouldn't modify filename. And you can just set filename = dest.

Samuel



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

2019-12-15 Thread Joan Lledó via Bug reports for the GNU Hurd
From: Joan Lledó 

* 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 | 12 
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/trans/remap.c b/trans/remap.c
index 5afbaa02..e3d5fa0a 100644
--- a/trans/remap.c
+++ b/trans/remap.c
@@ -65,19 +65,23 @@ trivfs_S_dir_lookup (struct trivfs_protid *diruser,
 mach_msg_type_name_t *retry_port_type)
 {
   struct remap *remap;
+  char dest[NAME_MAX] = { };
 
   if (!diruser)
 return EOPNOTSUPP;
 
   for (remap = remaps; remap; remap = remap->next)
-/* FIXME: should match just prefix of filename too */
-if (!strcmp (remap->from, filename))
+if (!strncmp (remap->from, filename, strlen (remap->from)))
   {
+   snprintf (dest, NAME_MAX, "%s%s", remap->to,
+ filename + strlen (remap->from));
+
 #ifdef DEBUG
-   fprintf (stderr,"replacing %s with %s\n", remap->from, remap->to);
+   fprintf (stderr, "replacing %s with %s\n", filename, dest);
fflush (stderr);
 #endif
-   filename = remap->to;
+
+   strncpy (filename, dest, NAME_MAX);
break;
   }
 
-- 
2.20.1