]> granicus.if.org Git - postgresql/commitdiff
If presented db path has a trailing slash, remove it to avoid generating
authorTom Lane <tgl@sss.pgh.pa.us>
Mon, 4 Mar 2002 04:45:27 +0000 (04:45 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Mon, 4 Mar 2002 04:45:27 +0000 (04:45 +0000)
double slashes in generated filenames.  This is not strictly necessary
on standard Unixen, but I'm being a neatnik...

src/backend/utils/init/miscinit.c

index 5019757832e5921d5003c5e016f59b510005e4a2..dceb8b9cd6f79800fbc39cddb6e9d83ccccb72a7 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/utils/init/miscinit.c,v 1.84 2002/03/02 21:39:33 momjian Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/utils/init/miscinit.c,v 1.85 2002/03/04 04:45:27 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -121,9 +121,11 @@ void
 SetDataDir(const char *dir)
 {
        char       *new;
+       int                     newlen;
 
        AssertArg(dir);
 
+       /* If presented path is relative, convert to absolute */
        if (dir[0] != '/')
        {
                char       *buf;
@@ -164,6 +166,14 @@ SetDataDir(const char *dir)
                        elog(FATAL, "out of memory");
        }
 
+       /*
+        * Strip any trailing slash.  Not strictly necessary, but avoids
+        * generating funny-looking paths to individual files.
+        */
+       newlen = strlen(new);
+       if (newlen > 1 && new[newlen-1] == '/')
+               new[newlen-1] = '\0';
+
        if (DataDir)
                free(DataDir);
        DataDir = new;