Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
2e6bc4b8
Commit
2e6bc4b8
authored
Oct 19, 2013
by
Peter Eisentraut
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move rmtree() from libpgport to libpgcommon
It requires pgfnames() from libpgcommon.
parent
ba7c5975
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
134 additions
and
113 deletions
+134
-113
src/bin/initdb/nls.mk
src/bin/initdb/nls.mk
+1
-1
src/common/Makefile
src/common/Makefile
+1
-1
src/common/rmtree.c
src/common/rmtree.c
+131
-0
src/port/dirmod.c
src/port/dirmod.c
+0
-110
src/tools/msvc/Mkvcbuild.pm
src/tools/msvc/Mkvcbuild.pm
+1
-1
No files found.
src/bin/initdb/nls.mk
View file @
2e6bc4b8
# src/bin/initdb/nls.mk
CATALOG_NAME
=
initdb
AVAIL_LANGUAGES
=
cs de es fr it ja pl pt_BR ru zh_CN
GETTEXT_FILES
=
findtimezone.c initdb.c ../../common/exec.c ../../common/fe_memutils.c ../../common/pgfnames.c ../../common/wait_error.c ../../port/dirmod.c
GETTEXT_FILES
=
findtimezone.c initdb.c ../../common/exec.c ../../common/fe_memutils.c ../../common/pgfnames.c ../../common/
rmtree.c ../../common/
wait_error.c ../../port/dirmod.c
GETTEXT_TRIGGERS
=
simple_prompt
src/common/Makefile
View file @
2e6bc4b8
...
...
@@ -23,7 +23,7 @@ include $(top_builddir)/src/Makefile.global
override CPPFLAGS
:
= -DFRONTEND $(CPPFLAGS)
LIBS
+=
$(PTHREAD_LIBS)
OBJS_COMMON
=
exec.o pgfnames.o relpath.o wait_error.o
OBJS_COMMON
=
exec.o pgfnames.o relpath.o
rmtree.o
wait_error.o
OBJS_FRONTEND
=
$(OBJS_COMMON)
fe_memutils.o
...
...
src/common/rmtree.c
0 → 100644
View file @
2e6bc4b8
/*-------------------------------------------------------------------------
*
* rmtree.c
*
* Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* src/common/rmtree.c
*
*-------------------------------------------------------------------------
*/
#ifndef FRONTEND
#include "postgres.h"
#else
#include "postgres_fe.h"
#endif
#include <unistd.h>
#include <sys/stat.h>
/*
* rmtree
*
* Delete a directory tree recursively.
* Assumes path points to a valid directory.
* Deletes everything under path.
* If rmtopdir is true deletes the directory too.
* Returns true if successful, false if there was any problem.
* (The details of the problem are reported already, so caller
* doesn't really have to say anything more, but most do.)
*/
bool
rmtree
(
const
char
*
path
,
bool
rmtopdir
)
{
bool
result
=
true
;
char
pathbuf
[
MAXPGPATH
];
char
**
filenames
;
char
**
filename
;
struct
stat
statbuf
;
/*
* we copy all the names out of the directory before we start modifying
* it.
*/
filenames
=
pgfnames
(
path
);
if
(
filenames
==
NULL
)
return
false
;
/* now we have the names we can start removing things */
for
(
filename
=
filenames
;
*
filename
;
filename
++
)
{
snprintf
(
pathbuf
,
MAXPGPATH
,
"%s/%s"
,
path
,
*
filename
);
/*
* It's ok if the file is not there anymore; we were just about to
* delete it anyway.
*
* This is not an academic possibility. One scenario where this
* happens is when bgwriter has a pending unlink request for a file in
* a database that's being dropped. In dropdb(), we call
* ForgetDatabaseFsyncRequests() to flush out any such pending unlink
* requests, but because that's asynchronous, it's not guaranteed that
* the bgwriter receives the message in time.
*/
if
(
lstat
(
pathbuf
,
&
statbuf
)
!=
0
)
{
if
(
errno
!=
ENOENT
)
{
#ifndef FRONTEND
elog
(
WARNING
,
"could not stat file or directory
\"
%s
\"
: %m"
,
pathbuf
);
#else
fprintf
(
stderr
,
_
(
"could not stat file or directory
\"
%s
\"
: %s
\n
"
),
pathbuf
,
strerror
(
errno
));
#endif
result
=
false
;
}
continue
;
}
if
(
S_ISDIR
(
statbuf
.
st_mode
))
{
/* call ourselves recursively for a directory */
if
(
!
rmtree
(
pathbuf
,
true
))
{
/* we already reported the error */
result
=
false
;
}
}
else
{
if
(
unlink
(
pathbuf
)
!=
0
)
{
if
(
errno
!=
ENOENT
)
{
#ifndef FRONTEND
elog
(
WARNING
,
"could not remove file or directory
\"
%s
\"
: %m"
,
pathbuf
);
#else
fprintf
(
stderr
,
_
(
"could not remove file or directory
\"
%s
\"
: %s
\n
"
),
pathbuf
,
strerror
(
errno
));
#endif
result
=
false
;
}
}
}
}
if
(
rmtopdir
)
{
if
(
rmdir
(
path
)
!=
0
)
{
#ifndef FRONTEND
elog
(
WARNING
,
"could not remove file or directory
\"
%s
\"
: %m"
,
path
);
#else
fprintf
(
stderr
,
_
(
"could not remove file or directory
\"
%s
\"
: %s
\n
"
),
path
,
strerror
(
errno
));
#endif
result
=
false
;
}
}
pgfnames_cleanup
(
filenames
);
return
result
;
}
src/port/dirmod.c
View file @
2e6bc4b8
...
...
@@ -351,116 +351,6 @@ pgwin32_is_junction(char *path)
#endif
/* defined(WIN32) && !defined(__CYGWIN__) */
/*
* rmtree
*
* Delete a directory tree recursively.
* Assumes path points to a valid directory.
* Deletes everything under path.
* If rmtopdir is true deletes the directory too.
* Returns true if successful, false if there was any problem.
* (The details of the problem are reported already, so caller
* doesn't really have to say anything more, but most do.)
*/
bool
rmtree
(
const
char
*
path
,
bool
rmtopdir
)
{
bool
result
=
true
;
char
pathbuf
[
MAXPGPATH
];
char
**
filenames
;
char
**
filename
;
struct
stat
statbuf
;
/*
* we copy all the names out of the directory before we start modifying
* it.
*/
filenames
=
pgfnames
(
path
);
if
(
filenames
==
NULL
)
return
false
;
/* now we have the names we can start removing things */
for
(
filename
=
filenames
;
*
filename
;
filename
++
)
{
snprintf
(
pathbuf
,
MAXPGPATH
,
"%s/%s"
,
path
,
*
filename
);
/*
* It's ok if the file is not there anymore; we were just about to
* delete it anyway.
*
* This is not an academic possibility. One scenario where this
* happens is when bgwriter has a pending unlink request for a file in
* a database that's being dropped. In dropdb(), we call
* ForgetDatabaseFsyncRequests() to flush out any such pending unlink
* requests, but because that's asynchronous, it's not guaranteed that
* the bgwriter receives the message in time.
*/
if
(
lstat
(
pathbuf
,
&
statbuf
)
!=
0
)
{
if
(
errno
!=
ENOENT
)
{
#ifndef FRONTEND
elog
(
WARNING
,
"could not stat file or directory
\"
%s
\"
: %m"
,
pathbuf
);
#else
fprintf
(
stderr
,
_
(
"could not stat file or directory
\"
%s
\"
: %s
\n
"
),
pathbuf
,
strerror
(
errno
));
#endif
result
=
false
;
}
continue
;
}
if
(
S_ISDIR
(
statbuf
.
st_mode
))
{
/* call ourselves recursively for a directory */
if
(
!
rmtree
(
pathbuf
,
true
))
{
/* we already reported the error */
result
=
false
;
}
}
else
{
if
(
unlink
(
pathbuf
)
!=
0
)
{
if
(
errno
!=
ENOENT
)
{
#ifndef FRONTEND
elog
(
WARNING
,
"could not remove file or directory
\"
%s
\"
: %m"
,
pathbuf
);
#else
fprintf
(
stderr
,
_
(
"could not remove file or directory
\"
%s
\"
: %s
\n
"
),
pathbuf
,
strerror
(
errno
));
#endif
result
=
false
;
}
}
}
}
if
(
rmtopdir
)
{
if
(
rmdir
(
path
)
!=
0
)
{
#ifndef FRONTEND
elog
(
WARNING
,
"could not remove file or directory
\"
%s
\"
: %m"
,
path
);
#else
fprintf
(
stderr
,
_
(
"could not remove file or directory
\"
%s
\"
: %s
\n
"
),
path
,
strerror
(
errno
));
#endif
result
=
false
;
}
}
pgfnames_cleanup
(
filenames
);
return
result
;
}
#if defined(WIN32) && !defined(__CYGWIN__)
#undef stat
...
...
src/tools/msvc/Mkvcbuild.pm
View file @
2e6bc4b8
...
...
@@ -74,7 +74,7 @@ sub mkvcbuild
win32error.c win32setlocale.c)
;
our
@pgcommonallfiles
=
qw(
exec.c pgfnames.c relpath.c wait_error.c)
;
exec.c pgfnames.c relpath.c
rmtree.c
wait_error.c)
;
our
@pgcommonfrontendfiles
=
(
@pgcommonallfiles
,
qw(fe_memutils.c)
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment