postgresql/contrib/pg_dumplo/utils.c

98 lines
1.7 KiB
C
Raw Normal View History

/* -------------------------------------------------------------------------
* pg_dumplo
*
2004-08-29 13:07:03 +08:00
* $PostgreSQL: pgsql/contrib/pg_dumplo/utils.c,v 1.9 2004/08/29 05:06:36 momjian 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];
2004-08-29 13:07:03 +08:00
int sz;
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
}
sz = strlen(path);
2004-08-29 13:07:03 +08:00
strncat(path, "/lo_dump.index", BUFSIZ - sz);
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)
{
sz = strlen(path);
2004-08-29 13:07:03 +08:00
strncat(path, "/lo_dump.index", BUFSIZ - sz);
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
}