diff options
Diffstat (limited to 'src/backend/storage/file/fd.c')
-rw-r--r-- | src/backend/storage/file/fd.c | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/src/backend/storage/file/fd.c b/src/backend/storage/file/fd.c index 27e53f41c8b..8816589787a 100644 --- a/src/backend/storage/file/fd.c +++ b/src/backend/storage/file/fd.c @@ -7,7 +7,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/storage/file/fd.c,v 1.76 2001/04/03 04:07:02 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/storage/file/fd.c,v 1.77 2001/05/25 15:34:50 momjian Exp $ * * NOTES: * @@ -742,21 +742,29 @@ PathNameOpenFile(FileName fileName, int fileFlags, int fileMode) File OpenTemporaryFile(void) { - char tempfilename[64]; + char tempfilepath[128]; File file; /* * Generate a tempfile name that's unique within the current * transaction */ - snprintf(tempfilename, sizeof(tempfilename), - "pg_sorttemp%d.%ld", MyProcPid, tempFileCounter++); + snprintf(tempfilepath, sizeof(tempfilepath), + "%s%c%d.%ld", SORT_TEMP_DIR, SEP_CHAR, MyProcPid, + tempFileCounter++); /* Open the file */ - file = FileNameOpenFile(tempfilename, + file = FileNameOpenFile(tempfilepath, O_RDWR | O_CREAT | O_TRUNC | PG_BINARY, 0600); if (file <= 0) - elog(ERROR, "Failed to create temporary file %s", tempfilename); + { + /* mkdir could fail if some one else already created it */ + mkdir(SORT_TEMP_DIR, S_IRWXU); + file = FileNameOpenFile(tempfilepath, + O_RDWR | O_CREAT | O_TRUNC | PG_BINARY, 0600); + if (file <= 0) + elog(ERROR, "Failed to create temporary file %s", tempfilepath); + } /* Mark it for deletion at close or EOXact */ VfdCache[file].fdstate |= FD_TEMPORARY; |