MCPcopy Create free account
hub / github.com/apache/cloudberry / CheckDataVersion

Function CheckDataVersion

src/bin/pg_resetwal/pg_resetwal.c:710–746  ·  view source on GitHub ↗

* Look at the version string stored in PG_VERSION and decide if this utility * can be run safely or not. * * We don't want to inject pg_control and WAL files that are for a different * major version; that can't do anything good. Note that we don't treat * mismatching version info in pg_control as a reason to bail out, because * recovering from a corrupted pg_control is one of the main reaso

Source from the content-addressed store, hash-verified

708 * to prevent simple user errors.
709 */
710static void
711CheckDataVersion(void)
712{
713 const char *ver_file = "PG_VERSION";
714 FILE *ver_fd;
715 char rawline[64];
716
717 if ((ver_fd = fopen(ver_file, "r")) == NULL)
718 {
719 pg_log_error("could not open file \"%s\" for reading: %m",
720 ver_file);
721 exit(1);
722 }
723
724 /* version number has to be the first line read */
725 if (!fgets(rawline, sizeof(rawline), ver_fd))
726 {
727 if (!ferror(ver_fd))
728 pg_log_error("unexpected empty file \"%s\"", ver_file);
729 else
730 pg_log_error("could not read file \"%s\": %m", ver_file);
731 exit(1);
732 }
733
734 /* strip trailing newline and carriage return */
735 (void) pg_strip_crlf(rawline);
736
737 if (strcmp(rawline, PG_MAJORVERSION) != 0)
738 {
739 pg_log_error("data directory is of wrong version");
740 pg_log_info("File \"%s\" contains \"%s\", which is not compatible with this program's version \"%s\".",
741 ver_file, rawline, PG_MAJORVERSION);
742 exit(1);
743 }
744
745 fclose(ver_fd);
746}
747
748
749/*

Callers 1

mainFunction · 0.85

Calls 1

pg_strip_crlfFunction · 0.85

Tested by

no test coverage detected