2000-11-22 08:00:55 +08:00
|
|
|
/* -------------------------------------------------------------------------
|
|
|
|
* pg_dumplo
|
|
|
|
*
|
2001-03-22 12:01:46 +08:00
|
|
|
* $Header: /cvsroot/pgsql/contrib/pg_dumplo/Attic/utils.c,v 1.4 2001/03/22 03:59:10 momjian Exp $
|
2000-11-22 08:00:55 +08:00
|
|
|
*
|
|
|
|
* Karel Zak 1999-2000
|
|
|
|
* -------------------------------------------------------------------------
|
|
|
|
*/
|
2000-06-16 03:05:22 +08:00
|
|
|
|
2001-03-22 12:01:46 +08:00
|
|
|
#include <stdio.h>
|
2000-06-16 03:05:22 +08:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#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 <libpq-fe.h>
|
|
|
|
#include <libpq/libpq-fs.h>
|
|
|
|
|
|
|
|
#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
|
|
|
|
|
|
|
sprintf(path, "%s/%s", pgLO->space, pgLO->db);
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2001-03-22 12:01:46 +08:00
|
|
|
sprintf(path, "%s/lo_dump.index", path);
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
|
|
|
|
sprintf(path, "%s/lo_dump.index", path);
|
|
|
|
|
|
|
|
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
|
|
|
}
|