|
1 | 1 | /* |
2 | | - * $PostgreSQL: pgsql/contrib/pg_archivecleanup/pg_archivecleanup.c,v 1.1 2010/06/14 16:19:24 sriggs Exp $ |
| 2 | + * $PostgreSQL: pgsql/contrib/pg_archivecleanup/pg_archivecleanup.c,v 1.2 2010/06/17 17:31:27 tgl Exp $ |
3 | 3 | * |
4 | 4 | * pg_archivecleanup.c |
5 | 5 | * |
@@ -43,7 +43,6 @@ charWALFilePath[MAXPGPATH];/* the file path including archive */ |
43 | 43 | charexclusiveCleanupFileName[MAXPGPATH];/* the oldest file we want to |
44 | 44 | * remain in archive */ |
45 | 45 |
|
46 | | -structstatstat_buf; |
47 | 46 |
|
48 | 47 | /* ===================================================================== |
49 | 48 | * |
@@ -78,10 +77,13 @@ Initialize(void) |
78 | 77 | * This code assumes that archiveLocation is a directory, so we use |
79 | 78 | * stat to test if it's accessible. |
80 | 79 | */ |
81 | | -if (stat(archiveLocation,&stat_buf)!=0) |
| 80 | +structstatstat_buf; |
| 81 | + |
| 82 | +if (stat(archiveLocation,&stat_buf)!=0|| |
| 83 | +!S_ISDIR(stat_buf.st_mode)) |
82 | 84 | { |
83 | | -fprintf(stderr,"%s: archiveLocation \"%s\" does not exist\n",progname,archiveLocation); |
84 | | -fflush(stderr); |
| 85 | +fprintf(stderr,"%s: archiveLocation \"%s\" does not exist\n", |
| 86 | +progname,archiveLocation); |
85 | 87 | exit(2); |
86 | 88 | } |
87 | 89 | } |
@@ -122,25 +124,23 @@ CleanupPriorWALFiles(void) |
122 | 124 | #endif |
123 | 125 |
|
124 | 126 | if (debug) |
125 | | -fprintf(stderr,"\n%s: removing \"%s\"",progname,WALFilePath); |
| 127 | +fprintf(stderr,"%s: removing file \"%s\"\n", |
| 128 | +progname,WALFilePath); |
126 | 129 |
|
127 | 130 | rc=unlink(WALFilePath); |
128 | 131 | if (rc!=0) |
129 | 132 | { |
130 | | -fprintf(stderr,"\n%s: ERROR failed to remove \"%s\": %s", |
| 133 | +fprintf(stderr,"%s: ERROR: could not removefile\"%s\": %s\n", |
131 | 134 | progname,WALFilePath,strerror(errno)); |
132 | 135 | break; |
133 | 136 | } |
134 | 137 | } |
135 | 138 | } |
136 | | -if (debug) |
137 | | -fprintf(stderr,"\n"); |
| 139 | +closedir(xldir); |
138 | 140 | } |
139 | 141 | else |
140 | | -fprintf(stderr,"%s: archiveLocation \"%s\" open error\n",progname,archiveLocation); |
141 | | - |
142 | | -closedir(xldir); |
143 | | -fflush(stderr); |
| 142 | +fprintf(stderr,"%s: could not open archiveLocation \"%s\": %s\n", |
| 143 | +progname,archiveLocation,strerror(errno)); |
144 | 144 | } |
145 | 145 |
|
146 | 146 | /* |
@@ -304,10 +304,8 @@ main(int argc, char **argv) |
304 | 304 | SetWALFileNameForCleanup(); |
305 | 305 |
|
306 | 306 | if (debug) |
307 | | -{ |
308 | | -fprintf(stderr,"%s: keep WAL file %s and later",progname,exclusiveCleanupFileName); |
309 | | -fflush(stderr); |
310 | | -} |
| 307 | +fprintf(stderr,"%s: keep WAL file \"%s\" and later\n", |
| 308 | +progname,exclusiveCleanupFileName); |
311 | 309 |
|
312 | 310 | /* |
313 | 311 | * Remove WAL files older than cut-off |
|