very elaborate mkdir error checking in pg_dump

Lists: pgsql-hackers
From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: very elaborate mkdir error checking in pg_dump
Date: 2012-07-19 18:59:39
Message-ID: 1342724379.13354.3.camel@vanquo.pezone.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Is there a real point to all this code in pg_backup_directory.c?

static void
createDirectory(const char *dir)
{
struct stat st;

/* the directory must not exist yet. */
if (stat(dir, &st) == 0)
{
if (S_ISDIR(st.st_mode))
exit_horribly(modulename,
"cannot create directory %s, it exists already\n",
dir);
else
exit_horribly(modulename,
"cannot create directory %s, a file with this name "
"exists already\n", dir);
}

/*
* Now we create the directory. Note that for some race condition we could
* also run into the situation that the directory has been created just
* between our two calls.
*/
if (mkdir(dir, 0700) < 0)
exit_horribly(modulename, "could not create directory %s: %s\n",
dir, strerror(errno));
}

Couldn't we just call mkdir() and report the strerrno(errno) to begin
with, like everyone else does?


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: very elaborate mkdir error checking in pg_dump
Date: 2012-07-19 19:15:20
Message-ID: 11269.1342725320@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Peter Eisentraut <peter_e(at)gmx(dot)net> writes:
> Couldn't we just call mkdir() and report the strerrno(errno) to begin
> with, like everyone else does?

+1. It'll provide pretty much the same information anyway.

regards, tom lane