/* * Verify that the given directory exists and is empty. If it does not * exist, it is created. If it exists but is not empty, an error will * be give and the process ended. */ static void verify_dir_is_empty_or_create(char *dirname) { switch (pg_check_dir(dirname)) { case 0: /* * Does not exist, so create */ if (pg_mkdir_p(dirname, S_IRWXU) == -1) { fprintf(stderr, _("%s: could not create directory \"%s\": %s\n"), progname, dirname, strerror(errno)); disconnect_and_exit(1); } return; case 1: /* * Exists, empty */ return; case 2: case 3: case 4: /* * Exists, not empty */ fprintf(stderr, _("%s: directory \"%s\" exists but is not empty\n"), progname, dirname); disconnect_and_exit(1); case -1: /* * Access problem */ fprintf(stderr, _("%s: could not access directory \"%s\": %s\n"), progname, dirname, strerror(errno)); disconnect_and_exit(1); } }
/* * make the data directory (or one of its subdirectories if subdir is not NULL) */ static bool mkdatadir(const char *subdir) { char *path; path = pg_malloc(strlen(pg_data) + 2 + (subdir == NULL ? 0 : strlen(subdir))); if (subdir != NULL) sprintf(path, "%s/%s", pg_data, subdir); else strcpy(path, pg_data); if (pg_mkdir_p(path, S_IRWXU) == 0) return true; fprintf(stderr, _("%s: could not create directory \"%s\": %s\n"), progname, path, strerror(errno)); return false; }