aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBruce Momjian <bruce@momjian.us>2006-06-27 01:16:58 +0000
committerBruce Momjian <bruce@momjian.us>2006-06-27 01:16:58 +0000
commitfe491fb9afd07f3cc9b8aabb17f43049b79258a9 (patch)
treef44f71df1b9c35621cf9addcd1948d8e8b0913e3 /src
parent560feb474a353f3a3ca5349c07638a7774850dab (diff)
downloadpostgresql-fe491fb9afd07f3cc9b8aabb17f43049b79258a9.tar.gz
postgresql-fe491fb9afd07f3cc9b8aabb17f43049b79258a9.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/bin/pg_dump/pg_backup_tar.c30
1 files changed, 29 insertions, 1 deletions
diff --git a/src/bin/pg_dump/pg_backup_tar.c b/src/bin/pg_dump/pg_backup_tar.c
index 5fa080b06ac..bd034757fda 100644
--- a/src/bin/pg_dump/pg_backup_tar.c
+++ b/src/bin/pg_dump/pg_backup_tar.c
@@ -16,7 +16,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_tar.c,v 1.52 2006/06/07 22:24:44 momjian Exp $
+ * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_tar.c,v 1.53 2006/06/27 01:16:58 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -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));