From: Christoph Moench-Tegeder Date: Sun, 15 Mar 2015 22:07:40 +0000 (+0100) Subject: bdr: fix open() flags of destination in copy_file() X-Git-Tag: bdr-plugin/0.9.0~37^2~8 X-Git-Url: http://git.postgresql.org/gitweb/static/%7B%7Bpguslink%28?a=commitdiff_plain;h=79e13da053e90826d97ac7d313b6bb1215d12301;p=2ndquadrant_bdr.git bdr: fix open() flags of destination in copy_file() - the destination file is not guaranteed to exist, so O_CREAT must be used. - O_TRUNC has to be set to make sure there will be no leftovers at the end of the file in case the destination file already existed. --- diff --git a/bdr_init_copy.c b/bdr_init_copy.c index 9041b4aa95..e21854ec32 100644 --- a/bdr_init_copy.c +++ b/bdr_init_copy.c @@ -1461,7 +1461,7 @@ copy_file(char *fromfile, char *tofile) if (srcfd < 0) die(_("could not open file \"%s\""), fromfile); - dstfd = open(tofile, O_RDWR | PG_BINARY, + dstfd = open(tofile, O_RDWR | O_CREAT | O_TRUNC | PG_BINARY, S_IRUSR | S_IWUSR); if (dstfd < 0) die(_("could not create file \"%s\""), tofile);