/*
- * $PostgreSQL: pgsql/contrib/pg_archivecleanup/pg_archivecleanup.c,v 1.1 2010/06/14 16:19:24 sriggs Exp $
+ * $PostgreSQL: pgsql/contrib/pg_archivecleanup/pg_archivecleanup.c,v 1.2 2010/06/17 17:31:27 tgl Exp $
*
* pg_archivecleanup.c
*
char exclusiveCleanupFileName[MAXPGPATH]; /* the oldest file we want to
* remain in archive */
-struct stat stat_buf;
/* =====================================================================
*
* This code assumes that archiveLocation is a directory, so we use
* stat to test if it's accessible.
*/
- if (stat(archiveLocation, &stat_buf) != 0)
+ struct stat stat_buf;
+
+ if (stat(archiveLocation, &stat_buf) != 0 ||
+ !S_ISDIR(stat_buf.st_mode))
{
- fprintf(stderr, "%s: archiveLocation \"%s\" does not exist\n", progname, archiveLocation);
- fflush(stderr);
+ fprintf(stderr, "%s: archiveLocation \"%s\" does not exist\n",
+ progname, archiveLocation);
exit(2);
}
}
#endif
if (debug)
- fprintf(stderr, "\n%s: removing \"%s\"", progname, WALFilePath);
+ fprintf(stderr, "%s: removing file \"%s\"\n",
+ progname, WALFilePath);
rc = unlink(WALFilePath);
if (rc != 0)
{
- fprintf(stderr, "\n%s: ERROR failed to remove \"%s\": %s",
+ fprintf(stderr, "%s: ERROR: could not remove file \"%s\": %s\n",
progname, WALFilePath, strerror(errno));
break;
}
}
}
- if (debug)
- fprintf(stderr, "\n");
+ closedir(xldir);
}
else
- fprintf(stderr, "%s: archiveLocation \"%s\" open error\n", progname, archiveLocation);
-
- closedir(xldir);
- fflush(stderr);
+ fprintf(stderr, "%s: could not open archiveLocation \"%s\": %s\n",
+ progname, archiveLocation, strerror(errno));
}
/*
SetWALFileNameForCleanup();
if (debug)
- {
- fprintf(stderr, "%s: keep WAL file %s and later", progname, exclusiveCleanupFileName);
- fflush(stderr);
- }
+ fprintf(stderr, "%s: keep WAL file \"%s\" and later\n",
+ progname, exclusiveCleanupFileName);
/*
* Remove WAL files older than cut-off