~ubuntu-branches/ubuntu/lucid/postgresql-8.4/lucid-proposed

« back to all changes in this revision

Viewing changes to src/bin/pg_resetxlog/pg_resetxlog.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2009-05-19 14:03:37 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20090519140337-wp9u2si99uppeb81
Tags: 8.4~beta2-2
* Second public beta of 8.4.
* debian/control: Slightly lower the dependencies for postgresql-common to
  >= 98~, so that backports also match.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
 * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
24
24
 * Portions Copyright (c) 1994, Regents of the University of California
25
25
 *
26
 
 * $PostgreSQL$
 
26
 * $PostgreSQL: pgsql/src/bin/pg_resetxlog/pg_resetxlog.c,v 1.73 2009/05/03 23:13:37 tgl Exp $
27
27
 *
28
28
 *-------------------------------------------------------------------------
29
29
 */
71
71
static void RewriteControlFile(void);
72
72
static void FindEndOfXLOG(void);
73
73
static void KillExistingXLOG(void);
 
74
static void KillExistingArchiveStatus(void);
74
75
static void WriteEmptyXLOG(void);
75
76
static void usage(void);
76
77
 
360
361
         */
361
362
        RewriteControlFile();
362
363
        KillExistingXLOG();
 
364
        KillExistingArchiveStatus();
363
365
        WriteEmptyXLOG();
364
366
 
365
367
        printf(_("Transaction log reset\n"));
812
814
 
813
815
 
814
816
/*
 
817
 * Remove existing archive status files
 
818
 */
 
819
static void
 
820
KillExistingArchiveStatus(void)
 
821
{
 
822
        DIR                *xldir;
 
823
        struct dirent *xlde;
 
824
        char            path[MAXPGPATH];
 
825
 
 
826
#define ARCHSTATDIR     XLOGDIR "/archive_status"
 
827
 
 
828
        xldir = opendir(ARCHSTATDIR);
 
829
        if (xldir == NULL)
 
830
        {
 
831
                fprintf(stderr, _("%s: could not open directory \"%s\": %s\n"),
 
832
                                progname, ARCHSTATDIR, strerror(errno));
 
833
                exit(1);
 
834
        }
 
835
 
 
836
        errno = 0;
 
837
        while ((xlde = readdir(xldir)) != NULL)
 
838
        {
 
839
                if (strspn(xlde->d_name, "0123456789ABCDEF") == 24 &&
 
840
                        (strcmp(xlde->d_name + 24, ".ready") == 0 ||
 
841
                         strcmp(xlde->d_name + 24, ".done")  == 0))
 
842
                {
 
843
                        snprintf(path, MAXPGPATH, "%s/%s", ARCHSTATDIR, xlde->d_name);
 
844
                        if (unlink(path) < 0)
 
845
                        {
 
846
                                fprintf(stderr, _("%s: could not delete file \"%s\": %s\n"),
 
847
                                                progname, path, strerror(errno));
 
848
                                exit(1);
 
849
                        }
 
850
                }
 
851
                errno = 0;
 
852
        }
 
853
#ifdef WIN32
 
854
 
 
855
        /*
 
856
         * This fix is in mingw cvs (runtime/mingwex/dirent.c rev 1.4), but not in
 
857
         * released version
 
858
         */
 
859
        if (GetLastError() == ERROR_NO_MORE_FILES)
 
860
                errno = 0;
 
861
#endif
 
862
 
 
863
        if (errno)
 
864
        {
 
865
                fprintf(stderr, _("%s: could not read from directory \"%s\": %s\n"),
 
866
                                progname, ARCHSTATDIR, strerror(errno));
 
867
                exit(1);
 
868
        }
 
869
        closedir(xldir);
 
870
}
 
871
 
 
872
 
 
873
/*
815
874
 * Write an empty XLOG file, containing only the checkpoint record
816
875
 * already set up in ControlFile.
817
876
 */