aboutsummaryrefslogtreecommitdiff
path: root/contrib/pg_dumplo/utils.c
blob: 644781b79cec0cbe5a767e4aa09cd259358a16b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/* -------------------------------------------------------------------------
 * pg_dumplo
 *
 * $PostgreSQL: pgsql/contrib/pg_dumplo/utils.c,v 1.9 2004/08/29 05:06:36 momjian Exp $
 *
 *					Karel Zak 1999-2000
 * -------------------------------------------------------------------------
 */

#include "postgres_fe.h"

#include <fcntl.h>
#include <errno.h>
#include <time.h>
#include <unistd.h>
#include <sys/stat.h>

#include "libpq-fe.h"
#include "libpq/libpq-fs.h"

#include "pg_dumplo.h"

extern int	errno;

static void Dummy_NoticeProcessor(void *arg, const char *message);
static void Default_NoticeProcessor(void *arg, const char *message);


void
index_file(LODumpMaster * pgLO)
{
	char		path[BUFSIZ];
	int			sz;

	if (pgLO->action == ACTION_SHOW)
		return;

	snprintf(path, BUFSIZ, "%s/%s", pgLO->space, pgLO->db);

	if (pgLO->action == ACTION_EXPORT_ATTR ||
		pgLO->action == ACTION_EXPORT_ALL)
	{

		if (mkdir(path, DIR_UMASK) == -1)
		{
			if (errno != EEXIST)
			{
				perror(path);
				exit(RE_ERROR);
			}
		}

		sz = strlen(path);
		strncat(path, "/lo_dump.index", BUFSIZ - sz);

		if ((pgLO->index = fopen(path, "w")) == NULL)
		{
			perror(path);
			exit(RE_ERROR);
		}

	}
	else if (pgLO->action != ACTION_NONE)
	{
		sz = strlen(path);
		strncat(path, "/lo_dump.index", BUFSIZ - sz);

		if ((pgLO->index = fopen(path, "r")) == NULL)
		{
			perror(path);
			exit(RE_ERROR);
		}
	}
}

static
void
Dummy_NoticeProcessor(void *arg, const char *message)
{
	;
}

static
void
Default_NoticeProcessor(void *arg, const char *message)
{
	fprintf(stderr, "%s", message);
}

void
notice(LODumpMaster * pgLO, int set)
{
	if (set)
		PQsetNoticeProcessor(pgLO->conn, Default_NoticeProcessor, NULL);
	else
		PQsetNoticeProcessor(pgLO->conn, Dummy_NoticeProcessor, NULL);
}