1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-13 07:41:39 +03:00

Adjust rename on Win32 to only link to temp name while holding lock,

then release locks and loop over renaming to active file name.
This commit is contained in:
Bruce Momjian
2004-02-02 00:17:23 +00:00
parent e5e5a323ca
commit d9d2ca8e8e
5 changed files with 67 additions and 27 deletions

View File

@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $PostgreSQL: pgsql/src/backend/commands/user.c,v 1.133 2004/01/26 22:35:32 tgl Exp $
* $PostgreSQL: pgsql/src/backend/commands/user.c,v 1.134 2004/02/02 00:17:21 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@ -139,7 +139,11 @@ write_group_file(Relation grel)
bufsize = strlen(filename) + 12;
tempname = (char *) palloc(bufsize);
snprintf(tempname, bufsize, "%s.%d", filename, MyProcPid);
#if defined(WIN32) || defined(CYGWIN)
filename = repalloc(filename, strlen(filename) + 1 + strlen(".new");
strcat(filename, ".new");
#endif
oumask = umask((mode_t) 077);
fp = AllocateFile(tempname, "w");
umask(oumask);
@ -286,6 +290,10 @@ write_user_file(Relation urel)
bufsize = strlen(filename) + 12;
tempname = (char *) palloc(bufsize);
snprintf(tempname, bufsize, "%s.%d", filename, MyProcPid);
#if defined(WIN32) || defined(CYGWIN)
filename = repalloc(filename, strlen(filename) + 1 + strlen(".new");
strcat(filename, ".new");
#endif
oumask = umask((mode_t) 077);
fp = AllocateFile(tempname, "w");
@ -457,6 +465,18 @@ AtEOXact_UpdatePasswordFile(bool isCommit)
user_file_update_needed = false;
write_user_file(urel);
heap_close(urel, NoLock);
#if defined(WIN32) || defined(CYGWIN)
{
/* Rename active file while not holding an exclusive lock */
char *filename = user_getfilename(), *filename_new;
filename_new = palloc(strlen(filename) + 1 + strlen(".new")));
sprintf(filename_new, "%s.new", filename);
rename(filename_new, filename);
pfree(filename);
pfree(filename_new);
}
#endif
}
if (group_file_update_needed)
@ -464,6 +484,18 @@ AtEOXact_UpdatePasswordFile(bool isCommit)
group_file_update_needed = false;
write_group_file(grel);
heap_close(grel, NoLock);
#if defined(WIN32) || defined(CYGWIN)
{
/* Rename active file while not holding an exclusive lock */
char *filename = group_getfilename(), *filename_new;
filename_new = palloc(strlen(filename) + 1 + strlen(".new")));
sprintf(filename_new, "%s.new", filename);
rename(filename_new, filename);
pfree(filename);
pfree(filename_new);
}
#endif
}
/*