/* * Create a BufFile for a new file. * * Does not add the pgsql_tmp/ prefix to the file path before creating. * */ BufFile * BufFileCreateFile(const char *fileName, bool delOnClose, bool interXact) { return BufFileOpenFile(fileName, true, /* create */ delOnClose, interXact); }
/* * Opens an existing work file with the specified name, the file type, * and the compression type. * * If this fails, NULL is returned. */ ExecWorkFile * ExecWorkFile_Open(const char *fileName, ExecWorkFileType fileType, bool delOnClose, int compressType) { ExecWorkFile *workfile = NULL; void *file = NULL; int64 file_size = 0; switch(fileType) { case BUFFILE: file = (void *)BufFileOpenFile(fileName, false, /* Create */ delOnClose, true /* interXact */ ); if (!file) { elog(ERROR, "could not open temporary file \"%s\": %m", fileName); } BufFileSetWorkfile(file); file_size = BufFileGetSize(file); break; case BFZ: file = (void *)bfz_open(fileName, delOnClose, compressType); if (!file) { elog(ERROR, "could not open temporary file \"%s\": %m", fileName); } file_size = bfz_totalbytes((bfz_t *)file); break; default: ereport(LOG, (errcode(ERRCODE_INTERNAL_ERROR), errmsg("invalid work file type: %d", fileType))); Assert(false); } /* Failed opening existing workfile. Inform the caller */ if (NULL == file) { return NULL; } workfile = palloc0(sizeof(ExecWorkFile)); workfile->fileType = fileType; workfile->compressType = compressType; workfile->file = file; workfile->fileName = pstrdup(fileName); workfile->size = file_size; ExecWorkFile_SetFlags(workfile, delOnClose, false /* created */); return workfile; }