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

Commite191a69

Browse files
committed
pg_upgrade: Don't overwrite existing files.
For historical reasons, copyFile and rewriteVisibilityMap took a forceargument which was always passed as true, meaning that any existingfile should be overwritten. However, it seems much safer to insteadfail if a file we need to write already exists.While we're at it, remove the "force" argument altogether, since it wasnever passed as anything other than true (and now we would never passit as anything other than false, if we kept it).Noted by Andres Freund during post-commit review of the patch that addedrewriteVisibilityMap, commit7087166,but this also changes the behavior when copying files without rewritingthem.Patch by Masahiko Sawada.
1 parent932b97a commite191a69

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

‎src/bin/pg_upgrade/file.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323

2424
#ifndefWIN32
25-
staticintcopy_file(constchar*fromfile,constchar*tofile,boolforce);
25+
staticintcopy_file(constchar*fromfile,constchar*tofile);
2626
#else
2727
staticintwin32_pghardlink(constchar*src,constchar*dst);
2828
#endif
@@ -34,12 +34,12 @@ static intwin32_pghardlink(const char *src, const char *dst);
3434
*Copies a relation file from src to dst.
3535
*/
3636
constchar*
37-
copyFile(constchar*src,constchar*dst,boolforce)
37+
copyFile(constchar*src,constchar*dst)
3838
{
3939
#ifndefWIN32
40-
if (copy_file(src,dst,force)==-1)
40+
if (copy_file(src,dst)==-1)
4141
#else
42-
if (CopyFile(src,dst,!force)==0)
42+
if (CopyFile(src,dst,true)==0)
4343
#endif
4444
returngetErrorText();
4545
else
@@ -68,7 +68,7 @@ linkFile(const char *src, const char *dst)
6868

6969
#ifndefWIN32
7070
staticint
71-
copy_file(constchar*srcfile,constchar*dstfile,boolforce)
71+
copy_file(constchar*srcfile,constchar*dstfile)
7272
{
7373
#defineCOPY_BUF_SIZE (50 * BLCKSZ)
7474

@@ -87,7 +87,7 @@ copy_file(const char *srcfile, const char *dstfile, bool force)
8787
if ((src_fd=open(srcfile,O_RDONLY,0))<0)
8888
return-1;
8989

90-
if ((dest_fd=open(dstfile,O_RDWR |O_CREAT |(force ?0 :O_EXCL),S_IRUSR |S_IWUSR))<0)
90+
if ((dest_fd=open(dstfile,O_RDWR |O_CREAT |O_EXCL,S_IRUSR |S_IWUSR))<0)
9191
{
9292
save_errno=errno;
9393

@@ -159,7 +159,7 @@ copy_file(const char *srcfile, const char *dstfile, bool force)
159159
* VACUUM.
160160
*/
161161
constchar*
162-
rewriteVisibilityMap(constchar*fromfile,constchar*tofile,boolforce)
162+
rewriteVisibilityMap(constchar*fromfile,constchar*tofile)
163163
{
164164
intsrc_fd=0;
165165
intdst_fd=0;
@@ -186,7 +186,7 @@ rewriteVisibilityMap(const char *fromfile, const char *tofile, bool force)
186186
returngetErrorText();
187187
}
188188

189-
if ((dst_fd=open(tofile,O_RDWR |O_CREAT |(force ?0 :O_EXCL),S_IRUSR |S_IWUSR))<0)
189+
if ((dst_fd=open(tofile,O_RDWR |O_CREAT |O_EXCL,S_IRUSR |S_IWUSR))<0)
190190
{
191191
close(src_fd);
192192
returngetErrorText();

‎src/bin/pg_upgrade/pg_upgrade.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -367,10 +367,9 @@ boolpid_lock_file_exists(const char *datadir);
367367

368368
/* file.c */
369369

370-
constchar*copyFile(constchar*src,constchar*dst,boolforce);
370+
constchar*copyFile(constchar*src,constchar*dst);
371371
constchar*linkFile(constchar*src,constchar*dst);
372-
constchar*rewriteVisibilityMap(constchar*fromfile,constchar*tofile,
373-
boolforce);
372+
constchar*rewriteVisibilityMap(constchar*fromfile,constchar*tofile);
374373

375374
voidcheck_hard_link(void);
376375
FILE*fopen_priv(constchar*path,constchar*mode);

‎src/bin/pg_upgrade/relfilenode.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,9 @@ transfer_relfile(FileNameMap *map, const char *type_suffix, bool vm_must_add_fro
248248

249249
/* Rewrite visibility map if needed */
250250
if (vm_must_add_frozenbit&& (strcmp(type_suffix,"_vm")==0))
251-
msg=rewriteVisibilityMap(old_file,new_file, true);
251+
msg=rewriteVisibilityMap(old_file,new_file);
252252
else
253-
msg=copyFile(old_file,new_file, true);
253+
msg=copyFile(old_file,new_file);
254254

255255
if (msg)
256256
pg_fatal("error while copying relation \"%s.%s\" (\"%s\" to \"%s\"): %s\n",
@@ -262,7 +262,7 @@ transfer_relfile(FileNameMap *map, const char *type_suffix, bool vm_must_add_fro
262262

263263
/* Rewrite visibility map if needed */
264264
if (vm_must_add_frozenbit&& (strcmp(type_suffix,"_vm")==0))
265-
msg=rewriteVisibilityMap(old_file,new_file, true);
265+
msg=rewriteVisibilityMap(old_file,new_file);
266266
else
267267
msg=linkFile(old_file,new_file);
268268

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp