postgresql/contrib/pg_dumplo/utils.c

96 lines
1.7 KiB
C
Raw Normal View History

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