Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 336ebee

Browse files
committed
copydir() is supposed to return on failure, not elog(ERROR). Reduce
ERROR to WARNING so we keep control.
1 parent d16b877 commit 336ebee

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

src/port/copydir.c

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
/*
22
* While "xcopy /e /i /q" works fine for copying directories, on Windows XP
3-
* it requires an Window handle which prevents it from working when invoked
3+
* it requires a Window handle which prevents it from working when invoked
44
* as a service.
5+
*
6+
* $Header: /cvsroot/pgsql/src/port/Attic/copydir.c,v 1.5 2003/09/10 20:12:01 tgl Exp $
57
*/
68

79
#include "postgres.h"
@@ -12,6 +14,14 @@
1214
#include <dirent.h>
1315

1416

17+
/*
18+
* copydir: copy a directory (we only need to go one level deep)
19+
*
20+
* Return 0 on success, nonzero on failure.
21+
*
22+
* NB: do not elog(ERROR) on failure. Return to caller so it can try to
23+
* clean up.
24+
*/
1525
int
1626
copydir(char *fromdir, char *todir)
1727
{
@@ -22,18 +32,18 @@ copydir(char *fromdir, char *todir)
2232

2333
if (mkdir(todir) != 0)
2434
{
25-
ereport(ERROR,
35+
ereport(WARNING,
2636
(errcode_for_file_access(),
2737
errmsg("could not create directory \"%s\": %m", todir)));
28-
return 1;
38+
return -1;
2939
}
3040
xldir = opendir(fromdir);
3141
if (xldir == NULL)
3242
{
33-
ereport(ERROR,
43+
ereport(WARNING,
3444
(errcode_for_file_access(),
3545
errmsg("could not open directory \"%s\": %m", fromdir)));
36-
return 1;
46+
return -1;
3747
}
3848

3949
while ((xlde = readdir(xldir)) != NULL)
@@ -42,14 +52,11 @@ copydir(char *fromdir, char *todir)
4252
snprintf(tofl, MAXPGPATH, "%s/%s", todir, xlde->d_name);
4353
if (CopyFile(fromfl, tofl, TRUE) < 0)
4454
{
45-
int save_errno = errno;
46-
47-
closedir(xldir);
48-
errno = save_errno;
49-
ereport(ERROR,
55+
ereport(WARNING,
5056
(errcode_for_file_access(),
5157
errmsg("could not copy file \"%s\": %m", fromfl)));
52-
return 1;
58+
closedir(xldir);
59+
return -1;
5360
}
5461
}
5562

0 commit comments

Comments
 (0)