From 6f0ed734b22abfb4298fee888498911a73fba08f Mon Sep 17 00:00:00 2001 From: Bruce Momjian Date: Tue, 27 Jun 2006 01:17:05 +0000 Subject: [PATCH] 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. --- src/bin/pg_dump/pg_backup_tar.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/bin/pg_dump/pg_backup_tar.c b/src/bin/pg_dump/pg_backup_tar.c index 59808f3cae..3b153adfdc 100644 --- a/src/bin/pg_dump/pg_backup_tar.c +++ b/src/bin/pg_dump/pg_backup_tar.c @@ -359,7 +359,35 @@ tarOpen(ArchiveHandle *AH, const char *filename, char mode) { tm = calloc(1, sizeof(TAR_MEMBER)); +#ifndef WIN32 tm->tmpFH = tmpfile(); +#else + /* + * On WIN32, tmpfile() generates a filename in the root directory, + * which requires administrative permissions on certain systems. + * Loop until we find a unique file name we can create. + */ + while (1) + { + char *name; + int fd; + + name = _tempnam(NULL, "pg_temp_"); + if (name == NULL) + break; + fd = open(name, O_RDWR | O_CREAT | O_EXCL | O_BINARY | + O_TEMPORARY, S_IREAD | S_IWRITE); + free(name); + + if (fd != -1) /* created a file */ + { + tm->tmpFH = fdopen(fd, "w+b"); + break; + } + else if (errno != EEXIST) /* failure other than file exists */ + break; + } +#endif if (tm->tmpFH == NULL) die_horribly(AH, modulename, "could not generate temporary file name: %s\n", strerror(errno)); -- 2.39.5