1111 *as a service.
1212 *
1313 * IDENTIFICATION
14- * $PostgreSQL: pgsql/src/port/copydir.c,v 1.29 2010/02/2200:11:05 stark Exp $
14+ * $PostgreSQL: pgsql/src/port/copydir.c,v 1.30 2010/02/2202:50:10 tgl Exp $
1515 *
1616 *-------------------------------------------------------------------------
1717 */
@@ -90,18 +90,18 @@ copydir(char *fromdir, char *todir, bool recurse)
9090else if (S_ISREG (fst .st_mode ))
9191copy_file (fromfile ,tofile );
9292}
93- Free (xldir );
93+ FreeDir (xldir );
9494
9595/*
96- * Be paranoid here and fsync all files to ensurewe catch problems .
96+ * Be paranoid here and fsync all files to ensurethe copy is really done .
9797 */
98- AllocateDir (fromdir );
98+ xldir = AllocateDir (todir );
9999if (xldir == NULL )
100100ereport (ERROR ,
101101(errcode_for_file_access (),
102- errmsg ("could not open directory \"%s\": %m" ,fromdir )));
102+ errmsg ("could not open directory \"%s\": %m" ,todir )));
103103
104- while ((xlde = ReadDir (xldir ,fromdir ))!= NULL )
104+ while ((xlde = ReadDir (xldir ,todir ))!= NULL )
105105{
106106struct stat fst ;
107107
@@ -111,25 +111,29 @@ copydir(char *fromdir, char *todir, bool recurse)
111111
112112snprintf (tofile ,MAXPGPATH ,"%s/%s" ,todir ,xlde -> d_name );
113113
114- /* We don't need to sync directories here since the recursive
115- * copydir will do it before it returns */
116- if (lstat (fromfile ,& fst )< 0 )
114+ /*
115+ * We don't need to sync subdirectories here since the recursive
116+ * copydir will do it before it returns
117+ */
118+ if (lstat (tofile ,& fst )< 0 )
117119ereport (ERROR ,
118120(errcode_for_file_access (),
119- errmsg ("could not stat file \"%s\": %m" ,fromfile )));
121+ errmsg ("could not stat file \"%s\": %m" ,tofile )));
122+
120123if (S_ISREG (fst .st_mode ))
121- {
122124fsync_fname (tofile );
123- }
124125}
125126FreeDir (xldir );
126127
127128#ifdef NOTYET
128- /* It's important to fsync the destination directory itself as
129+ /*
130+ * It's important to fsync the destination directory itself as
129131 * individual file fsyncs don't guarantee that the directory entry
130132 * for the file is synced. Recent versions of ext4 have made the
131133 * window much wider but it's been true for ext3 and other
132- * filesystems in the past
134+ * filesystems in the past.
135+ *
136+ * However we can't do this just yet, it has portability issues.
133137 */
134138fsync_fname (todir );
135139#endif
@@ -210,7 +214,6 @@ copy_file(char *fromfile, char *tofile)
210214}
211215
212216
213-
214217/*
215218 * fsync a file
216219 */