On 09/04/2012 02:25 PM, Andrew Dunstan wrote:
On 09/04/2012 10:42 AM, Alvaro Herrera wrote:
Somehow the verbose reporting of user relation files being copied does
not seem exceedingly useful; and I don't remember seeing that on Linux.
Yeah, and it does something odd anyway when it's not writing to a
terminal. Can we get rid of it, or make it only work in verbose mode?
The attached is an attempt to fix this. I think it handles most of
what's wrong with this. (The patch is bigger because the code currently
uses a variable called "fileno" - not a good idea.)
cheers
andrew
diff --git a/contrib/pg_upgrade/relfilenode.c b/contrib/pg_upgrade/relfilenode.c
index 33a867f..0a579d5 100644
--- a/contrib/pg_upgrade/relfilenode.c
+++ b/contrib/pg_upgrade/relfilenode.c
@@ -14,7 +14,6 @@
#include "catalog/pg_class.h"
#include "access/transam.h"
-
static void transfer_single_new_db(pageCnvCtx *pageConverter,
FileNameMap *maps, int size);
static void transfer_relfile(pageCnvCtx *pageConverter,
@@ -136,7 +135,7 @@ transfer_single_new_db(pageCnvCtx *pageConverter,
char **namelist = NULL;
int numFiles = 0;
int mapnum;
- int fileno;
+ int file_no;
bool vm_crashsafe_change = false;
old_dir[0] = '\0';
@@ -156,8 +155,8 @@ transfer_single_new_db(pageCnvCtx *pageConverter,
{
if (numFiles > 0)
{
- for (fileno = 0; fileno < numFiles; fileno++)
- pg_free(namelist[fileno]);
+ for (file_no = 0; file_no < numFiles; file_no++)
+ pg_free(namelist[file_no]);
pg_free(namelist);
}
@@ -171,7 +170,34 @@ transfer_single_new_db(pageCnvCtx *pageConverter,
maps[mapnum].old_relfilenode);
snprintf(new_file, sizeof(new_file), "%s/%u", maps[mapnum].new_dir,
maps[mapnum].new_relfilenode);
- pg_log(PG_REPORT, OVERWRITE_MESSAGE, old_file);
+ if (!isatty(fileno(stdout)))
+ {
+ /* don't try to be cute if we're not interactive */
+ pg_log(PG_REPORT, " %s\n", old_file);
+ }
+ else
+ {
+ /*
+ * print the largest rightmost part of the name that can fit
+ * within the message width.
+ */
+ int remove = strlen(old_file) - atoi(MESSAGE_WIDTH);
+ char *start = old_file;
+ char *sep;
+
+ if ( remove > 0 )
+ {
+ /*
+ * If it's a partial path. move past the
+ * first file path separator we find, so we don't
+ * print a partial path segment.
+ */
+ start += remove;
+ if ((sep = strpbrk(start,"/\\")) != NULL)
+ start = sep + 1;
+ }
+ pg_log(PG_REPORT, OVERWRITE_MESSAGE, start);
+ }
/*
* Copy/link the relation's primary file (segment 0 of main fork)
@@ -190,23 +216,23 @@ transfer_single_new_db(pageCnvCtx *pageConverter,
snprintf(file_pattern, sizeof(file_pattern), "%u_",
maps[mapnum].old_relfilenode);
- for (fileno = 0; fileno < numFiles; fileno++)
+ for (file_no = 0; file_no < numFiles; file_no++)
{
- char *vm_offset = strstr(namelist[fileno], "_vm");
+ char *vm_offset = strstr(namelist[file_no], "_vm");
bool is_vm_file = false;
/* Is a visibility map file? (name ends with _vm) */
if (vm_offset && strlen(vm_offset) == strlen("_vm"))
is_vm_file = true;
- if (strncmp(namelist[fileno], file_pattern,
+ if (strncmp(namelist[file_no], file_pattern,
strlen(file_pattern)) == 0 &&
(!is_vm_file || !vm_crashsafe_change))
{
snprintf(old_file, sizeof(old_file), "%s/%s", maps[mapnum].old_dir,
- namelist[fileno]);
+ namelist[file_no]);
snprintf(new_file, sizeof(new_file), "%s/%u%s", maps[mapnum].new_dir,
- maps[mapnum].new_relfilenode, strchr(namelist[fileno], '_'));
+ maps[mapnum].new_relfilenode, strchr(namelist[file_no], '_'));
unlink(new_file);
transfer_relfile(pageConverter, old_file, new_file,
@@ -225,15 +251,15 @@ transfer_single_new_db(pageCnvCtx *pageConverter,
snprintf(file_pattern, sizeof(file_pattern), "%u.",
maps[mapnum].old_relfilenode);
- for (fileno = 0; fileno < numFiles; fileno++)
+ for (file_no = 0; file_no < numFiles; file_no++)
{
- if (strncmp(namelist[fileno], file_pattern,
+ if (strncmp(namelist[file_no], file_pattern,
strlen(file_pattern)) == 0)
{
snprintf(old_file, sizeof(old_file), "%s/%s", maps[mapnum].old_dir,
- namelist[fileno]);
+ namelist[file_no]);
snprintf(new_file, sizeof(new_file), "%s/%u%s", maps[mapnum].new_dir,
- maps[mapnum].new_relfilenode, strchr(namelist[fileno], '.'));
+ maps[mapnum].new_relfilenode, strchr(namelist[file_no], '.'));
unlink(new_file);
transfer_relfile(pageConverter, old_file, new_file,
@@ -244,8 +270,8 @@ transfer_single_new_db(pageCnvCtx *pageConverter,
if (numFiles > 0)
{
- for (fileno = 0; fileno < numFiles; fileno++)
- pg_free(namelist[fileno]);
+ for (file_no = 0; file_no < numFiles; file_no++)
+ pg_free(namelist[file_no]);
pg_free(namelist);
}
}
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers