@@ -110,20 +110,38 @@ static void
110
110
transfer_single_new_db (pageCnvCtx * pageConverter ,
111
111
FileNameMap * maps ,int size )
112
112
{
113
+ char old_dir [MAXPGPATH ];
114
+ struct dirent * * namelist = NULL ;
115
+ int numFiles = 0 ;
113
116
int mapnum ;
117
+ int fileno ;
118
+
119
+ old_dir [0 ]= '\0' ;
114
120
115
121
for (mapnum = 0 ;mapnum < size ;mapnum ++ )
116
122
{
117
123
char old_file [MAXPGPATH ];
118
124
char new_file [MAXPGPATH ];
119
- struct dirent * * namelist = NULL ;
120
- int numFiles ;
125
+
126
+ /* Changed tablespaces? Need a new directory scan? */
127
+ if (strcmp (maps [mapnum ].old_dir ,old_dir )!= 0 )
128
+ {
129
+ if (numFiles > 0 )
130
+ {
131
+ for (fileno = 0 ;fileno < numFiles ;fileno ++ )
132
+ pg_free (namelist [fileno ]);
133
+ pg_free (namelist );
134
+ }
135
+
136
+ snprintf (old_dir ,sizeof (old_dir ),"%s" ,maps [mapnum ].old_dir );
137
+ numFiles = pg_scandir (old_dir ,& namelist ,NULL );
138
+ }
121
139
122
140
/* Copying files might take some time, so give feedback. */
123
141
124
- snprintf (old_file ,sizeof (old_file ),"%s/%u" ,maps [mapnum ].old_file ,
142
+ snprintf (old_file ,sizeof (old_file ),"%s/%u" ,maps [mapnum ].old_dir ,
125
143
maps [mapnum ].old_relfilenode );
126
- snprintf (new_file ,sizeof (new_file ),"%s/%u" ,maps [mapnum ].new_file ,
144
+ snprintf (new_file ,sizeof (new_file ),"%s/%u" ,maps [mapnum ].new_dir ,
127
145
maps [mapnum ].new_relfilenode );
128
146
pg_log (PG_REPORT ,OVERWRITE_MESSAGE ,old_file );
129
147
@@ -139,28 +157,27 @@ transfer_single_new_db(pageCnvCtx *pageConverter,
139
157
if (GET_MAJOR_VERSION (old_cluster .major_version ) >=804 )
140
158
{
141
159
/*
142
- *Now copy /link any fsm and vm files, if they exist
160
+ *Copy /link any fsm and vm files, if they exist
143
161
*/
144
162
snprintf (scandir_file_pattern ,sizeof (scandir_file_pattern ),"%u_" ,
145
163
maps [mapnum ].old_relfilenode );
146
- numFiles = pg_scandir (maps [mapnum ].old_file ,& namelist ,dir_matching_filenames );
147
164
148
- while ( numFiles -- )
165
+ for ( fileno = 0 ; fileno < numFiles ; fileno ++ )
149
166
{
150
- snprintf (old_file ,sizeof (old_file ),"%s/%s" ,maps [mapnum ].old_file ,
151
- namelist [numFiles ]-> d_name );
152
- snprintf (new_file ,sizeof (new_file ),"%s/%u%s" ,maps [mapnum ].new_file ,
153
- maps [mapnum ].new_relfilenode ,strchr (namelist [numFiles ]-> d_name ,'_' ));
154
-
155
- unlink (new_file );
156
- transfer_relfile (pageConverter ,old_file ,new_file ,
157
- maps [mapnum ].old_nspname ,maps [mapnum ].old_relname ,
158
- maps [mapnum ].new_nspname ,maps [mapnum ].new_relname );
159
-
160
- pg_free (namelist [numFiles ]);
167
+ if (strncmp (namelist [fileno ]-> d_name ,scandir_file_pattern ,
168
+ strlen (scandir_file_pattern ))== 0 )
169
+ {
170
+ snprintf (old_file ,sizeof (old_file ),"%s/%s" ,maps [mapnum ].old_dir ,
171
+ namelist [fileno ]-> d_name );
172
+ snprintf (new_file ,sizeof (new_file ),"%s/%u%s" ,maps [mapnum ].new_dir ,
173
+ maps [mapnum ].new_relfilenode ,strchr (namelist [fileno ]-> d_name ,'_' ));
174
+
175
+ unlink (new_file );
176
+ transfer_relfile (pageConverter ,old_file ,new_file ,
177
+ maps [mapnum ].old_nspname ,maps [mapnum ].old_relname ,
178
+ maps [mapnum ].new_nspname ,maps [mapnum ].new_relname );
179
+ }
161
180
}
162
-
163
- pg_free (namelist );
164
181
}
165
182
166
183
/*
@@ -172,23 +189,30 @@ transfer_single_new_db(pageCnvCtx *pageConverter,
172
189
*/
173
190
snprintf (scandir_file_pattern ,sizeof (scandir_file_pattern ),"%u." ,
174
191
maps [mapnum ].old_relfilenode );
175
- numFiles = pg_scandir (maps [mapnum ].old_file ,& namelist ,dir_matching_filenames );
176
192
177
- while ( numFiles -- )
193
+ for ( fileno = 0 ; fileno < numFiles ; fileno ++ )
178
194
{
179
- snprintf (old_file ,sizeof (old_file ),"%s/%s" ,maps [mapnum ].old_file ,
180
- namelist [numFiles ]-> d_name );
181
- snprintf (new_file ,sizeof (new_file ),"%s/%u%s" ,maps [mapnum ].new_file ,
182
- maps [mapnum ].new_relfilenode ,strchr (namelist [numFiles ]-> d_name ,'.' ));
183
-
184
- unlink (new_file );
185
- transfer_relfile (pageConverter ,old_file ,new_file ,
186
- maps [mapnum ].old_nspname ,maps [mapnum ].old_relname ,
187
- maps [mapnum ].new_nspname ,maps [mapnum ].new_relname );
195
+ if (strncmp (namelist [fileno ]-> d_name ,scandir_file_pattern ,
196
+ strlen (scandir_file_pattern ))== 0 )
197
+ {
198
+ snprintf (old_file ,sizeof (old_file ),"%s/%s" ,maps [mapnum ].old_dir ,
199
+ namelist [fileno ]-> d_name );
200
+ snprintf (new_file ,sizeof (new_file ),"%s/%u%s" ,maps [mapnum ].new_dir ,
201
+ maps [mapnum ].new_relfilenode ,strchr (namelist [fileno ]-> d_name ,'.' ));
188
202
189
- pg_free (namelist [numFiles ]);
203
+ unlink (new_file );
204
+ transfer_relfile (pageConverter ,old_file ,new_file ,
205
+ maps [mapnum ].old_nspname ,maps [mapnum ].old_relname ,
206
+ maps [mapnum ].new_nspname ,maps [mapnum ].new_relname );
207
+ }
190
208
}
209
+ }
191
210
211
+
212
+ if (numFiles > 0 )
213
+ {
214
+ for (fileno = 0 ;fileno < numFiles ;fileno ++ )
215
+ pg_free (namelist [fileno ]);
192
216
pg_free (namelist );
193
217
}
194
218
}