Help with autoindex on; missing slash for directories

Maxim Dounin mdounin at mdounin.ru
Tue Jul 21 22:08:06 MSD 2009


Hello!

On Fri, Jul 17, 2009 at 03:14:35PM +0400, Igor Sysoev wrote:

> On Fri, Jul 17, 2009 at 07:01:00AM +0400, Maxim Dounin wrote:
> 
> > Hello!
> > 
> > On Thu, Jul 16, 2009 at 04:25:16PM -0700, Yazz D. Atlas wrote:
> > 
> > > Maxim,
> > >
> > > Ok finally added the patch with the I believe the right stuff. Attached 
> > > is the patch and the log file.
> > >
> > > I just ran "GET http://localhost:88/static"
> > 
> > Ok, thanx.  According to
> > 
> > 2009/07/16 16:16:10 [debug] 20579#0: *2 http autoindex file: ".svn", type 4
> > 2009/07/16 16:16:10 [debug] 20579#0: *2 http autoindex file: "questionnaires", type 10
> > 2009/07/16 16:16:10 [debug] 20579#0: *2 http autoindex file: "site", type 10
> > 2009/07/16 16:16:10 [debug] 20579#0: *2 http autoindex file: "50x.html", type 8
> > 2009/07/16 16:16:10 [debug] 20579#0: *2 http autoindex file: "rev.txt", type 8
> > 2009/07/16 16:16:10 [debug] 20579#0: *2 http autoindex file: ".", type 4
> > 2009/07/16 16:16:10 [debug] 20579#0: *2 http autoindex file: "protocols", type 10
> > 2009/07/16 16:16:10 [debug] 20579#0: *2 http autoindex file: "video", type 10
> > 2009/07/16 16:16:10 [debug] 20579#0: *2 http autoindex file: "..", type 4
> > 2009/07/16 16:16:10 [debug] 20579#0: *2 http autoindex file: "content", type 10
> > 
> > the only directories here are '.svn', '.' and '..'.  It's symlinks 
> > to directories that has no slash now.
> > 
> > I'll take a look how to fix this properly.
> 
> I've reproduced this bug on FreeBSD too. Will look how to resolve this.

Attached patch fixes the problem.  It also fixes typo (DT_LINK 
instead of DT_LNK, not used in code) and removes Linux special 
case as dirent.d_type may be unset on other systems too (e.g. 
cd9660 on FreeBSD).

Also I've changed DT_UNKNOWN check to explicit one (instead of 
implicitly checking for 0) - on all systems I've seen it's 0, but 
AFAIK it's not guaranteed.

This patch was shamelessly tested with The CSRG Archives CD-ROM 1 
as shipped by Marshall Kirk McKusick.  :)

Maxim Dounin
-------------- next part --------------
diff -ur nginx-0.8.6-orig/src/os/unix/ngx_files.h nginx-0.8.6/src/os/unix/ngx_files.h
--- nginx-0.8.6-orig/src/os/unix/ngx_files.h	2009-07-21 21:10:06.000000000 +0400
+++ nginx-0.8.6/src/os/unix/ngx_files.h	2009-07-21 21:49:43.000000000 +0400
@@ -207,24 +207,20 @@
 
 #if (NGX_HAVE_D_TYPE)
 
-#if (NGX_LINUX)
-
-/* XFS on Linux does not set dirent.d_type */
+/*
+ * some filesystems (including XFS on Linux and cd9660 on FreeBSD)
+ * does not report dirent.d_type
+ */
 
 #define ngx_de_is_dir(dir)                                                   \
-    (((dir)->type) ? ((dir)->type == DT_DIR) : (S_ISDIR((dir)->info.st_mode)))
+    (((dir)->type == DT_UNKNOWN || (dir)->type == DT_LNK) ?                  \
+        (S_ISDIR((dir)->info.st_mode)) : ((dir)->type == DT_DIR))
 #define ngx_de_is_file(dir)                                                  \
-    (((dir)->type) ? ((dir)->type == DT_REG) : (S_ISREG((dir)->info.st_mode)))
+    (((dir)->type == DT_UNKNOWN || (dir)->type == DT_LNK) ?                  \
+        (S_ISREG((dir)->info.st_mode)) : ((dir)->type == DT_REG))
 #define ngx_de_is_link(dir)                                                  \
-    (((dir)->type) ? ((dir)->type == DT_LINK) : (S_ISLNK((dir)->info.st_mode)))
-
-#else
-
-#define ngx_de_is_dir(dir)       ((dir)->type == DT_DIR)
-#define ngx_de_is_file(dir)      ((dir)->type == DT_REG)
-#define ngx_de_is_link(dir)      ((dir)->type == DT_LINK)
-
-#endif /* NGX_LINUX */
+    (((dir)->type == DT_UNKNOWN) ?                                           \
+        (S_ISLNK((dir)->info.st_mode)) : ((dir)->type == DT_LNK))
 
 #else
 


More information about the nginx mailing list