bug-hurd
[Top][All Lists]
Advanced

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

Re: [PATCH] fix the trailing slash issue in dir_lookup calls


From: Flavio Cruz
Subject: Re: [PATCH] fix the trailing slash issue in dir_lookup calls
Date: Mon, 11 Jan 2016 02:16:08 +0100
User-agent: Mutt/1.5.24 (2015-08-30)

---

Samuel,

I'm sending a new version of patch, which includes the required changes
in both libnetfs and libdiskfs.

On Sun, Jan 03, 2016 at 01:42:23AM +0100, Samuel Thibault wrote:
> Flavio Cruz, on Sun 03 Jan 2016 01:35:55 +0100, wrote:
> > On Sun, Jan 03, 2016 at 01:27:17AM +0100, Samuel Thibault wrote:
> > > So you are making libc keep any heading slash, just dropping
> > > double-heading-slash, right?
> > 
> > Yes.
> 
> I'm wondering why keeping this heading slash, it seems unnecessary, and
> yet another thing that translators have to take care of.  Perhaps it
> would be not difficult to make sure to keep only the trailing slash,
> without keeping the heading slash? (and just a slash when no path is to
> be looked up).

Done. See patch below.

> 
> > > Does that work with current translators?
> > 
> > It appears to work fine so far, but it might require more stress testing
> > to be sure (like compiling a big project)
> 
> I don't think compiling stuff would be problematic, since it'd just open
> files. It's more corner cases which may pose problems (opening stuff in
> httpfs and whatnot).

I have tried it with hostmux/ftpfs and it seems to work fine so far. I'm
also running the patch on my Debian Hurd VM and no problems yet.

PS: there's a lot of code repetition all over libnetfs/libdiskfs. Maybe
some of the dir_lookup code should move to libfshelp. Also, there's
different formatting styles (spaces/tabs) in the same file. What about
automatically running gnu indent or clang-format when a file is
modified? This would help a lot when making modifications.

> 
> Samuel


diff --git a/hurd/lookup-retry.c b/hurd/lookup-retry.c
index f633e57..a64aeea 100644
--- a/hurd/lookup-retry.c
+++ b/hurd/lookup-retry.c
@@ -62,8 +62,14 @@ __hurd_file_name_lookup_retry (error_t (*use_init_port)
 
   error_t lookup_op (file_t startdir)
     {
-      while (file_name[0] == '/')
-       file_name++;
+      if (file_name[0] == '/' && file_name[1] != '\0')
+        {
+          while (file_name[1] == '/')
+            file_name++; /* Remove double leading slash.  */
+          /* Remove leading slash when we have more than the slash.  */
+          if (file_name[1] != '\0')
+            file_name++;
+        }
 
       return lookup_error ((*lookup) (startdir, file_name, flags, mode,
                                      &doretry, retryname, result));
--

---

Hurd patch starts here:

diff --git a/libdiskfs/dir-lookup.c b/libdiskfs/dir-lookup.c
index 75df9b8..25e84ab 100644
--- a/libdiskfs/dir-lookup.c
+++ b/libdiskfs/dir-lookup.c
@@ -161,7 +161,9 @@ diskfs_S_dir_lookup (struct protid *dircred,
                  *retry = FS_RETRY_REAUTH;
                  *returned_port = dircred->po->shadow_root_parent;
                  *returned_port_poly = MACH_MSG_TYPE_COPY_SEND;
-                 if (! lastcomp)
+                 if (lastcomp && mustbedir) /* Trailing slash.  */
+                    strcpy (retryname, "/");
+                 else if (!lastcomp)
                    strcpy (retryname, nextname);
                  err = 0;
                  goto out;
@@ -175,7 +177,9 @@ diskfs_S_dir_lookup (struct protid *dircred,
              *retry = FS_RETRY_REAUTH;
              *returned_port = dircred->po->root_parent;
              *returned_port_poly = MACH_MSG_TYPE_COPY_SEND;
-             if (!lastcomp)
+             if (lastcomp && mustbedir) /* Trailing slash.  */
+                strcpy (retryname, "/");
+             else if (!lastcomp)
                strcpy (retryname, nextname);
              err = 0;
              goto out;
@@ -213,7 +217,7 @@ diskfs_S_dir_lookup (struct protid *dircred,
 
       /* If this is translated, start the translator (if necessary)
         and return.  */
-      if ((((flags & O_NOTRANS) == 0) || !lastcomp)
+      if ((((flags & O_NOTRANS) == 0) || !lastcomp || mustbedir)
          && ((np->dn_stat.st_mode & S_IPTRANS)
              || S_ISFIFO (np->dn_stat.st_mode)
              || S_ISCHR (np->dn_stat.st_mode)
@@ -304,11 +308,16 @@ diskfs_S_dir_lookup (struct protid *dircred,
          if (err != ENOENT)
            {
              *returned_port_poly = MACH_MSG_TYPE_MOVE_SEND;
-             if (!lastcomp && !err)
-               {
+              if (!err)
+                {
                  char *end = strchr (retryname, '\0');
-                 *end++ = '/';
-                 strcpy (end, nextname);
+                  if (mustbedir)
+                    *end++ = '/'; /* Trailing slash.  */
+                  else if (!lastcomp) {
+                    if (end != retryname)
+                      *end++ = '/';
+                    strcpy (end, nextname);
+                  }
                }
 
              if (register_translator)
diff --git a/libnetfs/dir-lookup.c b/libnetfs/dir-lookup.c
index 8b8cd6e..0dcd3c3 100644
--- a/libnetfs/dir-lookup.c
+++ b/libnetfs/dir-lookup.c
@@ -128,7 +128,9 @@ netfs_S_dir_lookup (struct protid *diruser,
            *do_retry = FS_RETRY_REAUTH;
            *retry_port = diruser->po->shadow_root_parent;
            *retry_port_type = MACH_MSG_TYPE_COPY_SEND;
-           if (! lastcomp)
+           if (lastcomp && mustbedir) /* Trailing slash.  */
+             strcpy (retry_name, "/");
+           else if (!lastcomp)
              strcpy (retry_name, nextname);
            error = 0;
            pthread_mutex_unlock (&dnp->lock);
@@ -142,7 +144,9 @@ netfs_S_dir_lookup (struct protid *diruser,
            *do_retry = FS_RETRY_REAUTH;
            *retry_port = diruser->po->root_parent;
            *retry_port_type = MACH_MSG_TYPE_COPY_SEND;
-           if (!lastcomp)
+           if (lastcomp && mustbedir) /* Trailing slash.  */
+             strcpy (retry_name, "/");
+            else if (!lastcomp)
              strcpy (retry_name, nextname);
            error = 0;
            pthread_mutex_unlock (&dnp->lock);
@@ -194,7 +198,7 @@ netfs_S_dir_lookup (struct protid *diruser,
       if (error)
        goto out;
 
-      if ((((flags & O_NOTRANS) == 0) || !lastcomp)
+      if ((((flags & O_NOTRANS) == 0) || !lastcomp || mustbedir)
          && ((np->nn_translated & S_IPTRANS)
              || S_ISFIFO (np->nn_translated)
              || S_ISCHR (np->nn_translated)
@@ -288,10 +292,16 @@ netfs_S_dir_lookup (struct protid *diruser,
          if (error != ENOENT)
            {
              *retry_port_type = MACH_MSG_TYPE_MOVE_SEND;
-             if (!lastcomp && !error)
+             if (!error)
                {
-                 strcat (retry_name, "/");
-                 strcat (retry_name, nextname);
+                 char *end = strchr (retry_name, '\0');
+                  if (mustbedir)
+                    *end++ = '/'; /* Trailing slash.  */
+                  else if (!lastcomp) {
+                    if (end != retry_name)
+                     *end++ = '/';
+                    strcpy (end, nextname);
+                  }
                }
 
              if (register_translator)



reply via email to

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