Skip to content

Commit fe491fb

Browse files
committed
On Win32, use loop to create pg_dump temporary tar file in the current
directory, not in device root, for permission reasons. Backpatch to 8.1.X.
1 parent 560feb4 commit fe491fb

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

src/bin/pg_dump/pg_backup_tar.c

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*
1717
*
1818
* IDENTIFICATION
19-
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_tar.c,v 1.52 2006/06/07 22:24:44 momjian Exp $
19+
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_tar.c,v 1.53 2006/06/27 01:16:58 momjian Exp $
2020
*
2121
*-------------------------------------------------------------------------
2222
*/
@@ -359,7 +359,35 @@ tarOpen(ArchiveHandle *AH, const char *filename, char mode)
359359
{
360360
tm = calloc(1, sizeof(TAR_MEMBER));
361361

362+
#ifndef WIN32
362363
tm->tmpFH = tmpfile();
364+
#else
365+
/*
366+
* On WIN32, tmpfile() generates a filename in the root directory,
367+
* which requires administrative permissions on certain systems.
368+
* Loop until we find a unique file name we can create.
369+
*/
370+
while (1)
371+
{
372+
char *name;
373+
int fd;
374+
375+
name = _tempnam(NULL, "pg_temp_");
376+
if (name == NULL)
377+
break;
378+
fd = open(name, O_RDWR | O_CREAT | O_EXCL | O_BINARY |
379+
O_TEMPORARY, S_IREAD | S_IWRITE);
380+
free(name);
381+
382+
if (fd != -1) /* created a file */
383+
{
384+
tm->tmpFH = fdopen(fd, "w+b");
385+
break;
386+
}
387+
else if (errno != EEXIST) /* failure other than file exists */
388+
break;
389+
}
390+
#endif
363391

364392
if (tm->tmpFH == NULL)
365393
die_horribly(AH, modulename, "could not generate temporary file name: %s\n", strerror(errno));

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy