*** pgsql/src/port/dirmod.c 2008/04/18 06:48:50 1.51.2.3 --- pgsql/src/port/dirmod.c 2008/04/18 17:05:53 1.51.2.4 *************** *** 10,16 **** * Win32 (NT, Win2k, XP). replace() doesn't work on Win95/98/Me. * * IDENTIFICATION ! * $PostgreSQL: pgsql/src/port/dirmod.c,v 1.51.2.2 2008/04/11 23:59:49 tgl Exp $ * *------------------------------------------------------------------------- */ --- 10,16 ---- * Win32 (NT, Win2k, XP). replace() doesn't work on Win95/98/Me. * * IDENTIFICATION ! * $PostgreSQL: pgsql/src/port/dirmod.c,v 1.51.2.3 2008/04/18 06:48:50 heikki Exp $ * *------------------------------------------------------------------------- */ *************** pgsymlink(const char *oldpath, const cha *** 291,298 **** * must call pgfnames_cleanup later to free the memory allocated by this * function. */ ! char ** ! pgfnames(char *path) { DIR *dir; struct dirent *file; --- 291,298 ---- * must call pgfnames_cleanup later to free the memory allocated by this * function. */ ! char ** ! pgfnames(const char *path) { DIR *dir; struct dirent *file; *************** pgfnames_cleanup(char **filenames) *** 380,391 **** * Assumes path points to a valid directory. * Deletes everything under path. * If rmtopdir is true deletes the directory too. */ bool ! rmtree(char *path, bool rmtopdir) { char pathbuf[MAXPGPATH]; - char *filepath; char **filenames; char **filename; struct stat statbuf; --- 380,394 ---- * Assumes path points to a valid directory. * Deletes everything under path. * If rmtopdir is true deletes the directory too. + * Returns true if successful, false if there was any problem. + * (The details of the problem are reported already, so caller + * doesn't really have to say anything more, but most do.) */ bool ! rmtree(const char *path, bool rmtopdir) { + bool result = true; char pathbuf[MAXPGPATH]; char **filenames; char **filename; struct stat statbuf; *************** rmtree(char *path, bool rmtopdir) *** 400,410 **** 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); /* * It's ok if the file is not there anymore; we were just about to --- 403,411 ---- return false; /* now we have the names we can start removing things */ for (filename = filenames; *filename; filename++) { ! snprintf(pathbuf, MAXPGPATH, "%s/%s", path, *filename); /* * It's ok if the file is not there anymore; we were just about to *************** rmtree(char *path, bool rmtopdir) *** 417,470 **** * requests, but because that's asynchronous, it's not guaranteed * that the bgwriter receives the message in time. */ ! if (lstat(filepath, &statbuf) != 0) { if (errno != ENOENT) ! goto report_and_fail; ! else ! continue; } if (S_ISDIR(statbuf.st_mode)) { /* call ourselves recursively for a directory */ ! if (!rmtree(filepath, true)) { /* we already reported the error */ ! pgfnames_cleanup(filenames); ! return false; } } else { ! if (unlink(filepath) != 0) { if (errno != ENOENT) ! goto report_and_fail; } } } if (rmtopdir) { ! filepath = path; ! if (rmdir(filepath) != 0) ! goto report_and_fail; ! } ! ! pgfnames_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 pgfnames_cleanup(filenames); ! return false; } --- 418,485 ---- * requests, but because that's asynchronous, it's not guaranteed * that the bgwriter receives the message in time. */ ! if (lstat(pathbuf, &statbuf) != 0) { if (errno != ENOENT) ! { ! #ifndef FRONTEND ! elog(WARNING, "could not stat file or directory \"%s\": %m", ! pathbuf); ! #else ! fprintf(stderr, _("could not stat file or directory \"%s\": %s\n"), ! pathbuf, strerror(errno)); ! #endif ! result = false; ! } ! continue; } if (S_ISDIR(statbuf.st_mode)) { /* call ourselves recursively for a directory */ ! if (!rmtree(pathbuf, true)) { /* we already reported the error */ ! result = false; } } else { ! if (unlink(pathbuf) != 0) { if (errno != ENOENT) ! { ! #ifndef FRONTEND ! elog(WARNING, "could not remove file or directory \"%s\": %m", ! pathbuf); ! #else ! fprintf(stderr, _("could not remove file or directory \"%s\": %s\n"), ! pathbuf, strerror(errno)); ! #endif ! result = false; ! } } } } if (rmtopdir) { ! if (rmdir(path) != 0) ! { #ifndef FRONTEND ! elog(WARNING, "could not remove file or directory \"%s\": %m", ! path); #else ! fprintf(stderr, _("could not remove file or directory \"%s\": %s\n"), ! path, strerror(errno)); #endif + result = false; + } + } + pgfnames_cleanup(filenames); ! ! return result; }