if ((res = malloc(size)) == NULL)
{
- fprintf(stderr, gettext("out of memory\n"));
+ fprintf(stderr, "out of memory\n");
exit(1);
}
return res;
if ((res = strdup(string)) == NULL)
{
- fprintf(stderr, gettext("out of memory\n"));
+ fprintf(stderr, "out of memory\n");
exit(1);
}
return res;
if ((res = realloc(pointer, size)) == NULL)
{
- fprintf(stderr, gettext("out of memory\n"));
+ fprintf(stderr, "out of memory\n");
exit(1);
}
return res;
#ifndef FRONTEND
ereport(ERROR,
(errcode_for_file_access(),
- errmsg("Error setting junction for %s: %s",
+ errmsg("could not set junction for \"%s\": %s",
nativeTarget, msg)));
#else
- fprintf(stderr, "Error setting junction for %s: %s\n",
+ fprintf(stderr, "could not set junction for \"%s\": %s\n",
nativeTarget, msg);
#endif
LocalFree(msg);
dir = opendir(path);
if (dir == NULL)
+ {
+#ifndef FRONTEND
+ elog(WARNING, "could not open directory \"%s\": %m", path);
+#else
+ fprintf(stderr, "could not open directory \"%s\": %s\n",
+ path, strerror(errno));
+#endif
return NULL;
+ }
filenames = (char **) palloc(fnsize * sizeof(char *));
+ errno = 0;
while ((file = readdir(dir)) != NULL)
{
if (strcmp(file->d_name, ".") != 0 && strcmp(file->d_name, "..") != 0)
}
filenames[numnames++] = pstrdup(file->d_name);
}
+ errno = 0;
+ }
+#ifdef WIN32
+
+ /*
+ * This fix is in mingw cvs (runtime/mingwex/dirent.c rev 1.4), but
+ * not in released version
+ */
+ if (GetLastError() == ERROR_NO_MORE_FILES)
+ errno = 0;
+#endif
+ if (errno)
+ {
+#ifndef FRONTEND
+ elog(WARNING, "could not read directory \"%s\": %m", path);
+#else
+ fprintf(stderr, "could not read directory \"%s\": %s\n",
+ path, strerror(errno));
+#endif
}
filenames[numnames] = NULL;
return filenames;
}
+
/*
* fnames_cleanup
*
pfree(filenames);
}
+
/*
* rmtree
*
bool
rmtree(char *path, bool rmtopdir)
{
- char filepath[MAXPGPATH];
+ char pathbuf[MAXPGPATH];
+ char *filepath;
char **filenames;
char **filename;
struct stat statbuf;
return false;
/* now we have the names we can start removing things */
+ filepath = pathbuf;
for (filename = filenames; *filename; filename++)
{
snprintf(filepath, MAXPGPATH, "%s/%s", path, *filename);
if (stat(filepath, &statbuf) != 0)
- {
- fnames_cleanup(filenames);
- return false;
- }
+ goto report_and_fail;
if (S_ISDIR(statbuf.st_mode))
{
/* call ourselves recursively for a directory */
if (!rmtree(filepath, true))
{
+ /* we already reported the error */
fnames_cleanup(filenames);
return false;
}
else
{
if (unlink(filepath) != 0)
- {
- fnames_cleanup(filenames);
- return false;
- }
+ goto report_and_fail;
}
}
if (rmtopdir)
{
- if (rmdir(path) != 0)
- {
- fnames_cleanup(filenames);
- return false;
- }
+ filepath = path;
+ if (rmdir(filepath) != 0)
+ goto report_and_fail;
}
fnames_cleanup(filenames);
return true;
+
+report_and_fail:
+
+#ifndef FRONTEND
+ elog(WARNING, "could not remove file or directory \"%s\": %m", filepath);
+#else
+ fprintf(stderr, "could not remove file or directory \"%s\": %s\n",
+ filepath, strerror(errno));
+#endif
+ fnames_cleanup(filenames);
+ return false;
}