Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4bfb75a

Browse files
committed
Change initdb to not delete PGDATA directory unless it was created by
initdb itself. Refuse to run on existing but non-empty PGDATA directory.
1 parent424f0ed commit4bfb75a

File tree

2 files changed

+27
-23
lines changed

2 files changed

+27
-23
lines changed

‎src/bin/initdb/Makefile

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#
55
# Copyright (c) 1994, Regents of the University of California
66
#
7-
# $Header: /cvsroot/pgsql/src/bin/initdb/Makefile,v 1.21 2000/08/31 16:11:06 petere Exp $
7+
# $Header: /cvsroot/pgsql/src/bin/initdb/Makefile,v 1.22 2000/09/01 13:15:27 petere Exp $
88
#
99
#-------------------------------------------------------------------------
1010

@@ -15,11 +15,14 @@ include $(top_builddir)/src/Makefile.global
1515
all: initdb
1616

1717
initdb: initdb.sh$(top_builddir)/src/Makefile.global
18-
sed -e's/__MULTIBYTE__/$(MULTIBYTE)/g'\
19-
-e's/__VERSION__/$(VERSION)/g'\
20-
-e's:__bindir__:$(bindir):g'\
21-
-e's:__datadir__:$(datadir):g'\
22-
<$<>$@
18+
rm -f$@$@.tmp
19+
sed -e's/@MULTIBYTE@/$(MULTIBYTE)/g'\
20+
-e's/@VERSION@/$(VERSION)/g'\
21+
-e's,@bindir@,$(bindir),g'\
22+
-e's,@datadir@,$(datadir),g'\
23+
$<>$@.tmp
24+
chmod a+x$@.tmp
25+
mv$@.tmp$@
2326

2427
install: all installdirs
2528
$(INSTALL_SCRIPT) initdb$(bindir)/initdb

‎src/bin/initdb/initdb.sh

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#
2424
# Copyright (c) 1994, Regents of the University of California
2525
#
26-
# $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.102 2000/08/06 04:39:22 tgl Exp $
26+
# $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.103 2000/09/01 13:15:27 petere Exp $
2727
#
2828
#-------------------------------------------------------------------------
2929

@@ -37,8 +37,10 @@ exit_nicely(){
3737
echo
3838
echo"$CMDNAME failed."
3939
if ["$noclean"!= yes ];then
40-
echo"Removing$PGDATA."
41-
rm -rf"$PGDATA"||echo"Failed."
40+
if ["$template_only"!= yes ]&& ["$made_new_pgdata"= yes ];then
41+
echo"Removing$PGDATA."
42+
rm -rf"$PGDATA"||echo"Failed."
43+
fi
4244
echo"Removing temp file$TEMPFILE."
4345
rm -rf"$TEMPFILE"||echo"Failed."
4446
else
@@ -51,13 +53,13 @@ exit_nicely(){
5153
CMDNAME=`basename$0`
5254

5355
# Placed here during build
54-
VERSION=__VERSION__
55-
bindir='__bindir__'
56+
VERSION='@VERSION@'
57+
bindir='@bindir@'
5658
# Note that "datadir" is not the directory we're initializing, it's
5759
# merely how Autoconf names PREFIX/share.
58-
datadir='__datadir__'
60+
datadir='@datadir@'
5961
# as set by configure --enable-multibyte[=XXX].
60-
MULTIBYTE=__MULTIBYTE__
62+
MULTIBYTE='@MULTIBYTE@'
6163

6264
if ["$TMPDIR" ];then
6365
TEMPFILE="$TMPDIR/initdb.$$"
@@ -107,7 +109,7 @@ for prog in postgres pg_id
107109
do
108110
if [!-x"$PGPATH/$prog" ]
109111
then
110-
echo"The program$prog needed by$CMDNAME could not be found. It was"
112+
echo"The program\`$prog' needed by$CMDNAME could not be found. It was"
111113
echo"expected at:"
112114
echo"$PGPATH/$prog"
113115
echo"If this is not the correct directory, please start$CMDNAME"
@@ -368,24 +370,23 @@ echo
368370
# umask must disallow access to group, other for files and dirs
369371
umask 077
370372

371-
if [-f"$PGDATA"/PG_VERSION ]
373+
# find out if directory is empty
374+
pgdata_contents=`ls -A"$PGDATA"2>/dev/null`
375+
if [ x"$pgdata_contents"!= x ]
372376
then
373377
if ["$template_only"!= yes ]
374378
then
375-
echo"$CMDNAME: The file$PGDATA/PG_VERSION already exists."
376-
echo"This probably means initdb has already been run and the"
377-
echo"database system already exists."
378-
echo
379-
echo"If you want to create a new database system, either remove"
380-
echo"the directory$PGDATA or run initdb with a --pgdata argument"
379+
echo"$CMDNAME: The directory$PGDATA is exists but is not empty."
380+
echo"If you want to create a new database system, either remove or empty"
381+
echo"the directory$PGDATA or run initdb with an argument"
381382
echo"other than$PGDATA."
382383
exit 1
383384
fi
384385
else
385-
if [!-d"$PGDATA" ]
386-
then
386+
if [!-d"$PGDATA" ];then
387387
echo"Creating directory$PGDATA"
388388
mkdir"$PGDATA"|| exit_nicely
389+
made_new_pgdata=yes
389390
else
390391
echo"Fixing permissions on existing directory$PGDATA"
391392
chmod go-rwx"$PGDATA"|| exit_nicely

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp