From: | Haribabu kommi <haribabu(dot)kommi(at)huawei(dot)com> |
---|---|
To: | Andres Freund <andres(at)2ndquadrant(dot)com> |
Cc: | Fujii Masao <masao(dot)fujii(at)gmail(dot)com>, Magnus Hagander <magnus(at)hagander(dot)net>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: New option for pg_basebackup, to specify a different directory for pg_xlog |
Date: | 2013-11-19 07:41:02 |
Message-ID: | 8977CB36860C5843884E0A18D8747B0372BEE6E1@szxeml558-mbs.china.huawei.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On 18 November 2013 23:25 Andres Freund wrote:
> On 2013-11-18 15:01:42 +0000, Haribabu kommi wrote:
> >
> > /*
> > + * Returns the malloced string of containing current working
> directory.
> > + * The caller has to take care of freeing the memory.
> > + * On failure exits with error code.
> > + */
> > +static char *
> > +get_current_working_dir()
> > +{
> > + char *buf;
> > + size_t buflen;
> > +
> > + buflen = MAXPGPATH;
> > + for (;;)
> > + {
> > + buf = pg_malloc(buflen);
> > + if (getcwd(buf, buflen))
> > + break;
> > + else if (errno == ERANGE)
> > + {
> > + pg_free(buf);
> > + buflen *= 2;
> > + continue;
> > + }
> > + else
> > + {
> > + pg_free(buf);
> > + fprintf(stderr,
> > + _("%s: could not get current working
> directory: %s\n"),
> > + progname, strerror(errno));
> > + exit(1);
> > + }
> > + }
> > +
> > + return buf;
> > +}
> > +
> > +/*
> > + * calculates the absolute path for the given path. The output
> > +absolute path
> > + * is a malloced string. The caller needs to take care of freeing
> the memory.
> > + */
> > +static char *
> > +get_absolute_path(const char *input_path) {
> > + char *pwd = NULL;
> > + char *abspath = NULL;
> > +
> > + /* Getting the present working directory */
> > + pwd = get_current_working_dir();
> > +
> > + if (chdir(input_path) < 0)
> > + {
> > + /* Directory doesn't exist */
> > + if (errno == ENOENT)
> > + return NULL;
> > +
> > + fprintf(stderr, _("%s: could not change directory to
> \"%s\": %s\n"),
> > + progname, input_path, strerror(errno));
> > + exit(1);
> > + }
> > +
> > + abspath = get_current_working_dir();
> > +
> > + /* Returning back to old working directory */
> > + if (chdir(pwd) < 0)
> > + {
> > + fprintf(stderr, _("%s: could not change directory to
> \"%s\": %s\n"),
> > + progname, pwd, strerror(errno));
> > + exit(1);
> > + }
> > +
> > + pg_free(pwd);
> > + return abspath;
> > +}
>
> This looks like it should be replaced by moving make_absolute_path from
> pg_regress.c to path.[ch] and then use that.
The "get_absolute_path" function removes any parent references, if exists, in the path
But the "make_absolute_path" doesn't. In this patch proper path is required to compare
The xlog and data directories provided are same or not?
I find two ways to do this
1. change to that provided directory and get the current working directory.
2. Write a function to remove the parent references in the path.
This patch has implemented the first approach. Please let me know your suggestions.
Regards,
Hari babu.
From | Date | Subject | |
---|---|---|---|
Next Message | Pavel Golub | 2013-11-19 08:04:47 | Re: LISTEN / NOTIFY enhancement request for Postgresql |
Previous Message | Peter Geoghegan | 2013-11-19 07:16:05 | Re: Improvement of pg_stat_statement usage about buffer hit ratio |