Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4da8fc0

Browse files
committed
Simplify pg_upgrade's handling when returning directory listings.
Backpatch to 9.2.
1 parentaf026b5 commit4da8fc0

File tree

3 files changed

+17
-26
lines changed

3 files changed

+17
-26
lines changed

‎contrib/pg_upgrade/file.c

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -225,23 +225,21 @@ copy_file(const char *srcfile, const char *dstfile, bool force)
225225
* load_directory()
226226
*
227227
* Read all the file names in the specified directory, and return them as
228-
* an array of "struct dirent" pointers. The array address is returned in
228+
* an array of "char *" pointers. The array address is returned in
229229
* *namelist, and the function result is the count of file names.
230230
*
231-
* To free the result data, free eachnamelist array member, then free the
231+
* To free the result data, free each(char *) array member, then free the
232232
* namelist array itself.
233233
*/
234234
int
235-
load_directory(constchar*dirname,structdirent***namelist)
235+
load_directory(constchar*dirname,char***namelist)
236236
{
237237
DIR*dirdesc;
238238
structdirent*direntry;
239239
intcount=0;
240-
intallocsize=64;
241-
size_tentrysize;
240+
intallocsize=64;/* initial array size */
242241

243-
*namelist= (structdirent**)
244-
pg_malloc(allocsize*sizeof(structdirent*));
242+
*namelist= (char**)pg_malloc(allocsize*sizeof(char*));
245243

246244
if ((dirdesc=opendir(dirname))==NULL)
247245
pg_log(PG_FATAL,"could not open directory \"%s\": %s\n",
@@ -252,18 +250,11 @@ load_directory(const char *dirname, struct dirent *** namelist)
252250
if (count >=allocsize)
253251
{
254252
allocsize *=2;
255-
*namelist= (structdirent**)
256-
pg_realloc(*namelist,allocsize*sizeof(structdirent*));
253+
*namelist= (char**)
254+
pg_realloc(*namelist,allocsize*sizeof(char*));
257255
}
258256

259-
entrysize= offsetof(structdirent,d_name)+
260-
strlen(direntry->d_name)+1;
261-
262-
(*namelist)[count]= (structdirent*)pg_malloc(entrysize);
263-
264-
memcpy((*namelist)[count],direntry,entrysize);
265-
266-
count++;
257+
(*namelist)[count++]=pg_strdup(direntry->d_name);
267258
}
268259

269260
#ifdefWIN32

‎contrib/pg_upgrade/pg_upgrade.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ const char *setupPageConverter(pageCnvCtx **result);
356356
typedefvoid*pageCnvCtx;
357357
#endif
358358

359-
intload_directory(constchar*dirname,structdirent***namelist);
359+
intload_directory(constchar*dirname,char***namelist);
360360
constchar*copyAndUpdateFile(pageCnvCtx*pageConverter,constchar*src,
361361
constchar*dst,boolforce);
362362
constchar*linkAndUpdateFile(pageCnvCtx*pageConverter,constchar*src,

‎contrib/pg_upgrade/relfilenode.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ transfer_single_new_db(pageCnvCtx *pageConverter,
133133
{
134134
charold_dir[MAXPGPATH];
135135
charfile_pattern[MAXPGPATH];
136-
structdirent**namelist=NULL;
136+
char**namelist=NULL;
137137
intnumFiles=0;
138138
intmapnum;
139139
intfileno;
@@ -192,21 +192,21 @@ transfer_single_new_db(pageCnvCtx *pageConverter,
192192

193193
for (fileno=0;fileno<numFiles;fileno++)
194194
{
195-
char*vm_offset=strstr(namelist[fileno]->d_name,"_vm");
195+
char*vm_offset=strstr(namelist[fileno],"_vm");
196196
boolis_vm_file= false;
197197

198198
/* Is a visibility map file? (name ends with _vm) */
199199
if (vm_offset&&strlen(vm_offset)==strlen("_vm"))
200200
is_vm_file= true;
201201

202-
if (strncmp(namelist[fileno]->d_name,file_pattern,
202+
if (strncmp(namelist[fileno],file_pattern,
203203
strlen(file_pattern))==0&&
204204
(!is_vm_file|| !vm_crashsafe_change))
205205
{
206206
snprintf(old_file,sizeof(old_file),"%s/%s",maps[mapnum].old_dir,
207-
namelist[fileno]->d_name);
207+
namelist[fileno]);
208208
snprintf(new_file,sizeof(new_file),"%s/%u%s",maps[mapnum].new_dir,
209-
maps[mapnum].new_relfilenode,strchr(namelist[fileno]->d_name,'_'));
209+
maps[mapnum].new_relfilenode,strchr(namelist[fileno],'_'));
210210

211211
unlink(new_file);
212212
transfer_relfile(pageConverter,old_file,new_file,
@@ -227,13 +227,13 @@ transfer_single_new_db(pageCnvCtx *pageConverter,
227227

228228
for (fileno=0;fileno<numFiles;fileno++)
229229
{
230-
if (strncmp(namelist[fileno]->d_name,file_pattern,
230+
if (strncmp(namelist[fileno],file_pattern,
231231
strlen(file_pattern))==0)
232232
{
233233
snprintf(old_file,sizeof(old_file),"%s/%s",maps[mapnum].old_dir,
234-
namelist[fileno]->d_name);
234+
namelist[fileno]);
235235
snprintf(new_file,sizeof(new_file),"%s/%u%s",maps[mapnum].new_dir,
236-
maps[mapnum].new_relfilenode,strchr(namelist[fileno]->d_name,'.'));
236+
maps[mapnum].new_relfilenode,strchr(namelist[fileno],'.'));
237237

238238
unlink(new_file);
239239
transfer_relfile(pageConverter,old_file,new_file,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp