summaryrefslogtreecommitdiff
path: root/src/port/copydir.c
diff options
context:
space:
mode:
authorBruce Momjian2003-05-15 17:59:17 +0000
committerBruce Momjian2003-05-15 17:59:17 +0000
commit09aad5a3a67338e7b2dc83e6b9799c580e6511ab (patch)
tree6b3c6047dcb47c24d06bacc329c7cb833e15407f /src/port/copydir.c
parentbee0ac67ee35e578404d7ae476cd3cc82b275154 (diff)
Add copydir() function because xcopy doesn't work in XP without a
window.
Diffstat (limited to 'src/port/copydir.c')
-rw-r--r--src/port/copydir.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/port/copydir.c b/src/port/copydir.c
new file mode 100644
index 00000000000..cd39f4d07ee
--- /dev/null
+++ b/src/port/copydir.c
@@ -0,0 +1,44 @@
+/*
+ * While "xcopy /e /i /q" works fine for copying directories, on Windows XP
+ * it requires an Window handle which prevents it from working when invoked
+ * as a service.
+ */
+
+#include "postgres.h"
+
+int
+copydir(char *fromdir,char *todir)
+{
+ DIR *xldir;
+ struct dirent *xlde;
+ char fromfl[MAXPGPATH];
+ char tofl[MAXPGPATH];
+
+ if (mkdir(todir) != 0)
+ {
+ elog(ERROR, "could not make directory '%s'",todir);
+ return 1;
+ }
+ xldir = opendir(fromdir);
+ if (xldir == NULL)
+ {
+ closedir(xldir);
+ elog(ERROR, "could not open directory '%s'",fromdir);
+ return 1;
+ }
+
+ while ((xlde = readdir(xldir)) != NULL)
+ {
+ snprintf(fromfl, MAXPGPATH, "%s/%s", fromdir, xlde->d_name);
+ snprintf(tofl, MAXPGPATH, "%s/%s", todir, xlde->d_name);
+ if (CopyFile(fromfl,tofl,TRUE) < 0)
+ {
+ closedir(xldir);
+ elog(ERROR,"could not create file %s\n",todir);
+ return 1;
+ }
+ }
+
+ closedir(xldir);
+ return 0;
+}