static void *xmalloc0(int size);
static void usage(void);
static void verify_dir_is_empty_or_create(char *dirname);
-static void progress_report(int tablespacenum, char *fn);
+static void progress_report(int tablespacenum, const char *filename);
static PGconn *GetConnection(void);
static void ReceiveTarFile(PGconn *conn, PGresult *res, int rownum);
* is enabled, also print the current file name.
*/
static void
-progress_report(int tablespacenum, char *fn)
+progress_report(int tablespacenum, const char *filename)
{
int percent = (int) ((totaldone / 1024) * 100 / totalsize);
if (verbose)
{
- if (!fn)
+ if (!filename)
/*
* No filename given, so clear the status line (used for last
INT64_FORMAT "/" INT64_FORMAT " kB (%d%%) %d/%d tablespaces (%-30.30s)\r",
totaldone / 1024, totalsize,
percent,
- tablespacenum, tablespacecount, fn);
+ tablespacenum, tablespacecount, filename);
}
else
fprintf(stderr, INT64_FORMAT "/" INT64_FORMAT " kB (%d%%) %d/%d tablespaces\r",
static void
ReceiveTarFile(PGconn *conn, PGresult *res, int rownum)
{
- char fn[MAXPGPATH];
+ char filename[MAXPGPATH];
char *copybuf = NULL;
FILE *tarfile = NULL;
#ifdef HAVE_LIBZ
if (compresslevel != 0)
{
- snprintf(fn, sizeof(fn), "%s/base.tar.gz", basedir);
- ztarfile = gzopen(fn, "wb");
+ snprintf(filename, sizeof(filename), "%s/base.tar.gz", basedir);
+ ztarfile = gzopen(filename, "wb");
if (gzsetparams(ztarfile, compresslevel, Z_DEFAULT_STRATEGY) != Z_OK)
{
fprintf(stderr, _("%s: could not set compression level %d: %s\n"),
else
#endif
{
- snprintf(fn, sizeof(fn), "%s/base.tar", basedir);
- tarfile = fopen(fn, "wb");
+ snprintf(filename, sizeof(filename), "%s/base.tar", basedir);
+ tarfile = fopen(filename, "wb");
}
}
else
#ifdef HAVE_LIBZ
if (compresslevel != 0)
{
- snprintf(fn, sizeof(fn), "%s/%s.tar.gz", basedir, PQgetvalue(res, rownum, 0));
- ztarfile = gzopen(fn, "wb");
+ snprintf(filename, sizeof(filename), "%s/%s.tar.gz", basedir, PQgetvalue(res, rownum, 0));
+ ztarfile = gzopen(filename, "wb");
if (gzsetparams(ztarfile, compresslevel, Z_DEFAULT_STRATEGY) != Z_OK)
{
fprintf(stderr, _("%s: could not set compression level %d: %s\n"),
else
#endif
{
- snprintf(fn, sizeof(fn), "%s/%s.tar", basedir, PQgetvalue(res, rownum, 0));
- tarfile = fopen(fn, "wb");
+ snprintf(filename, sizeof(filename), "%s/%s.tar", basedir, PQgetvalue(res, rownum, 0));
+ tarfile = fopen(filename, "wb");
}
}
{
/* Compression is in use */
fprintf(stderr, _("%s: could not create compressed file \"%s\": %s\n"),
- progname, fn, get_gz_error(ztarfile));
+ progname, filename, get_gz_error(ztarfile));
disconnect_and_exit(1);
}
}
if (!tarfile)
{
fprintf(stderr, _("%s: could not create file \"%s\": %s\n"),
- progname, fn, strerror(errno));
+ progname, filename, strerror(errno));
disconnect_and_exit(1);
}
}
if (gzwrite(ztarfile, zerobuf, sizeof(zerobuf)) != sizeof(zerobuf))
{
fprintf(stderr, _("%s: could not write to compressed file \"%s\": %s\n"),
- progname, fn, get_gz_error(ztarfile));
+ progname, filename, get_gz_error(ztarfile));
}
}
else
if (fwrite(zerobuf, sizeof(zerobuf), 1, tarfile) != 1)
{
fprintf(stderr, _("%s: could not write to file \"%s\": %s\n"),
- progname, fn, strerror(errno));
+ progname, filename, strerror(errno));
disconnect_and_exit(1);
}
}
if (gzwrite(ztarfile, copybuf, r) != r)
{
fprintf(stderr, _("%s: could not write to compressed file \"%s\": %s\n"),
- progname, fn, get_gz_error(ztarfile));
+ progname, filename, get_gz_error(ztarfile));
}
}
else
if (fwrite(copybuf, r, 1, tarfile) != 1)
{
fprintf(stderr, _("%s: could not write to file \"%s\": %s\n"),
- progname, fn, strerror(errno));
+ progname, filename, strerror(errno));
disconnect_and_exit(1);
}
}
totaldone += r;
if (showprogress)
- progress_report(rownum, fn);
+ progress_report(rownum, filename);
} /* while (1) */
if (copybuf != NULL)
ReceiveAndUnpackTarFile(PGconn *conn, PGresult *res, int rownum)
{
char current_path[MAXPGPATH];
- char fn[MAXPGPATH];
+ char filename[MAXPGPATH];
int current_len_left;
int current_padding = 0;
char *copybuf = NULL;
/*
* First part of header is zero terminated filename
*/
- snprintf(fn, sizeof(fn), "%s/%s", current_path, copybuf);
- if (fn[strlen(fn) - 1] == '/')
+ snprintf(filename, sizeof(filename), "%s/%s", current_path, copybuf);
+ if (filename[strlen(filename) - 1] == '/')
{
/*
* Ends in a slash means directory or symlink to directory
/*
* Directory
*/
- fn[strlen(fn) - 1] = '\0'; /* Remove trailing slash */
- if (mkdir(fn, S_IRWXU) != 0)
+ filename[strlen(filename) - 1] = '\0'; /* Remove trailing slash */
+ if (mkdir(filename, S_IRWXU) != 0)
{
fprintf(stderr,
_("%s: could not create directory \"%s\": %s\n"),
- progname, fn, strerror(errno));
+ progname, filename, strerror(errno));
disconnect_and_exit(1);
}
#ifndef WIN32
- if (chmod(fn, (mode_t) filemode))
+ if (chmod(filename, (mode_t) filemode))
fprintf(stderr, _("%s: could not set permissions on directory \"%s\": %s\n"),
- progname, fn, strerror(errno));
+ progname, filename, strerror(errno));
#endif
}
else if (copybuf[156] == '2')
/*
* Symbolic link
*/
- fn[strlen(fn) - 1] = '\0'; /* Remove trailing slash */
- if (symlink(©buf[157], fn) != 0)
+ filename[strlen(filename) - 1] = '\0'; /* Remove trailing slash */
+ if (symlink(©buf[157], filename) != 0)
{
fprintf(stderr,
_("%s: could not create symbolic link from \"%s\" to \"%s\": %s\n"),
- progname, fn, ©buf[157], strerror(errno));
+ progname, filename, ©buf[157], strerror(errno));
disconnect_and_exit(1);
}
}
/*
* regular file
*/
- file = fopen(fn, "wb");
+ file = fopen(filename, "wb");
if (!file)
{
fprintf(stderr, _("%s: could not create file \"%s\": %s\n"),
- progname, fn, strerror(errno));
+ progname, filename, strerror(errno));
disconnect_and_exit(1);
}
#ifndef WIN32
- if (chmod(fn, (mode_t) filemode))
+ if (chmod(filename, (mode_t) filemode))
fprintf(stderr, _("%s: could not set permissions on file \"%s\": %s\n"),
- progname, fn, strerror(errno));
+ progname, filename, strerror(errno));
#endif
if (current_len_left == 0)
if (fwrite(copybuf, r, 1, file) != 1)
{
fprintf(stderr, _("%s: could not write to file \"%s\": %s\n"),
- progname, fn, strerror(errno));
+ progname, filename, strerror(errno));
disconnect_and_exit(1);
}
totaldone += r;
if (showprogress)
- progress_report(rownum, fn);
+ progress_report(rownum, filename);
current_len_left -= r;
if (current_len_left == 0 && current_padding == 0)