postgresql/src/port/copydir.c

66 lines
1.4 KiB
C
Raw Normal View History

/*
* While "xcopy /e /i /q" works fine for copying directories, on Windows XP
* it requires a Window handle which prevents it from working when invoked
* as a service.
*
* $Header: /cvsroot/pgsql/src/port/Attic/copydir.c,v 1.5 2003/09/10 20:12:01 tgl Exp $
*/
#include "postgres.h"
2003-08-04 02:43:34 +02:00
#undef mkdir /* no reason to use that macro because we
* ignore the 2nd arg */
2003-07-27 19:10:07 +02:00
#include <dirent.h>
/*
* copydir: copy a directory (we only need to go one level deep)
*
* Return 0 on success, nonzero on failure.
*
* NB: do not elog(ERROR) on failure. Return to caller so it can try to
* clean up.
*/
int
2003-08-04 02:43:34 +02:00
copydir(char *fromdir, char *todir)
{
DIR *xldir;
struct dirent *xlde;
char fromfl[MAXPGPATH];
char tofl[MAXPGPATH];
if (mkdir(todir) != 0)
{
ereport(WARNING,
2003-07-27 19:10:07 +02:00
(errcode_for_file_access(),
errmsg("could not create directory \"%s\": %m", todir)));
return -1;
}
xldir = opendir(fromdir);
if (xldir == NULL)
{
ereport(WARNING,
2003-07-27 19:10:07 +02:00
(errcode_for_file_access(),
errmsg("could not open directory \"%s\": %m", fromdir)));
return -1;
}
while ((xlde = readdir(xldir)) != NULL)
{
2003-08-04 02:43:34 +02:00
snprintf(fromfl, MAXPGPATH, "%s/%s", fromdir, xlde->d_name);
snprintf(tofl, MAXPGPATH, "%s/%s", todir, xlde->d_name);
if (CopyFile(fromfl, tofl, TRUE) < 0)
{
ereport(WARNING,
2003-08-04 02:43:34 +02:00
(errcode_for_file_access(),
errmsg("could not copy file \"%s\": %m", fromfl)));
closedir(xldir);
return -1;
2003-08-04 02:43:34 +02:00
}
}
closedir(xldir);
return 0;
}