Re: New option for pg_basebackup, to specify a different directory for pg_xlog - Mailing list pgsql-hackers

From Haribabu kommi
Subject Re: New option for pg_basebackup, to specify a different directory for pg_xlog
Date
Msg-id 8977CB36860C5843884E0A18D8747B0372BEE6E1@szxeml558-mbs.china.huawei.com
Whole thread Raw
In response to Re: New option for pg_basebackup, to specify a different directory for pg_xlog  (Andres Freund <andres@2ndquadrant.com>)
List 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.



pgsql-hackers by date:

Previous
From: Peter Geoghegan
Date:
Subject: Re: Improvement of pg_stat_statement usage about buffer hit ratio
Next
From: Pavel Golub
Date:
Subject: Re: LISTEN / NOTIFY enhancement request for Postgresql