postgresql/contrib/pg_dumplo/utils.c

98 lines
1.7 KiB
C
Raw Normal View History

/* -------------------------------------------------------------------------
* pg_dumplo
*
2003-11-29 20:52:15 +01:00
* $PostgreSQL: pgsql/contrib/pg_dumplo/utils.c,v 1.8 2003/11/29 19:51:35 pgsql Exp $
*
* Karel Zak 1999-2000
* -------------------------------------------------------------------------
*/
2000-06-15 21:05:22 +02:00
#include "postgres_fe.h"
2000-06-15 21:05:22 +02:00
#include <fcntl.h>
2001-03-22 05:01:46 +01:00
#include <errno.h>
2000-06-15 21:05:22 +02:00
#include <time.h>
#include <unistd.h>
#include <sys/stat.h>
2000-06-15 21:05:22 +02:00
#include "libpq-fe.h"
#include "libpq/libpq-fs.h"
2000-06-15 21:05:22 +02:00
#include "pg_dumplo.h"
2001-03-22 05:01:46 +01:00
extern int errno;
static void Dummy_NoticeProcessor(void *arg, const char *message);
static void Default_NoticeProcessor(void *arg, const char *message);
2000-06-15 21:05:22 +02:00
void
2001-03-22 05:01:46 +01:00
index_file(LODumpMaster * pgLO)
2000-06-15 21:05:22 +02:00
{
2001-03-22 05:01:46 +01:00
char path[BUFSIZ];
int sz;
2000-06-15 21:05:22 +02:00
if (pgLO->action == ACTION_SHOW)
return;
2001-03-22 05:01:46 +01:00
snprintf(path, BUFSIZ, "%s/%s", pgLO->space, pgLO->db);
2001-03-22 05:01:46 +01:00
2000-06-15 21:05:22 +02:00
if (pgLO->action == ACTION_EXPORT_ATTR ||
2001-03-22 05:01:46 +01:00
pgLO->action == ACTION_EXPORT_ALL)
{
if (mkdir(path, DIR_UMASK) == -1)
{
if (errno != EEXIST)
{
2000-06-15 21:05:22 +02:00
perror(path);
2001-03-22 05:01:46 +01:00
exit(RE_ERROR);
}
2000-06-15 21:05:22 +02:00
}
sz = strlen(path);
strncat(path, "/lo_dump.index", BUFSIZ-sz);
2001-03-22 05:01:46 +01:00
if ((pgLO->index = fopen(path, "w")) == NULL)
{
2000-06-15 21:05:22 +02:00
perror(path);
exit(RE_ERROR);
}
2001-03-22 05:01:46 +01:00
}
else if (pgLO->action != ACTION_NONE)
{
sz = strlen(path);
strncat(path, "/lo_dump.index", BUFSIZ-sz);
2001-03-22 05:01:46 +01:00
if ((pgLO->index = fopen(path, "r")) == NULL)
{
2000-06-15 21:05:22 +02:00
perror(path);
exit(RE_ERROR);
}
}
}
2001-03-22 05:01:46 +01:00
static
void
Dummy_NoticeProcessor(void *arg, const char *message)
2000-06-15 21:05:22 +02:00
{
2001-03-22 05:01:46 +01:00
;
2000-06-15 21:05:22 +02:00
}
2001-03-22 05:01:46 +01:00
static
void
Default_NoticeProcessor(void *arg, const char *message)
2000-06-15 21:05:22 +02:00
{
2001-03-22 05:01:46 +01:00
fprintf(stderr, "%s", message);
2000-06-15 21:05:22 +02:00
}
2001-03-22 05:01:46 +01:00
void
notice(LODumpMaster * pgLO, int set)
{
if (set)
PQsetNoticeProcessor(pgLO->conn, Default_NoticeProcessor, NULL);
else
PQsetNoticeProcessor(pgLO->conn, Dummy_NoticeProcessor, NULL);
2000-06-15 21:05:22 +02:00
}