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
6b711cf3
Commit
6b711cf3
authored
Nov 24, 2012
by
Bruce Momjian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
In pg_upgrade, simplify function copy_file() by using pg_malloc() and
centralizing error/shutdown code.
parent
16e1ae77
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
41 deletions
+13
-41
contrib/pg_upgrade/file.c
contrib/pg_upgrade/file.c
+13
-41
No files found.
contrib/pg_upgrade/file.c
View file @
6b711cf3
...
@@ -133,6 +133,8 @@ copy_file(const char *srcfile, const char *dstfile, bool force)
...
@@ -133,6 +133,8 @@ copy_file(const char *srcfile, const char *dstfile, bool force)
int
src_fd
;
int
src_fd
;
int
dest_fd
;
int
dest_fd
;
char
*
buffer
;
char
*
buffer
;
int
ret
=
0
;
int
save_errno
=
0
;
if
((
srcfile
==
NULL
)
||
(
dstfile
==
NULL
))
if
((
srcfile
==
NULL
)
||
(
dstfile
==
NULL
))
return
-
1
;
return
-
1
;
...
@@ -150,17 +152,6 @@ copy_file(const char *srcfile, const char *dstfile, bool force)
...
@@ -150,17 +152,6 @@ copy_file(const char *srcfile, const char *dstfile, bool force)
buffer
=
(
char
*
)
pg_malloc
(
COPY_BUF_SIZE
);
buffer
=
(
char
*
)
pg_malloc
(
COPY_BUF_SIZE
);
if
(
buffer
==
NULL
)
{
if
(
src_fd
!=
0
)
close
(
src_fd
);
if
(
dest_fd
!=
0
)
close
(
dest_fd
);
return
-
1
;
}
/* perform data copying i.e read src source, write to destination */
/* perform data copying i.e read src source, write to destination */
while
(
true
)
while
(
true
)
{
{
...
@@ -168,19 +159,9 @@ copy_file(const char *srcfile, const char *dstfile, bool force)
...
@@ -168,19 +159,9 @@ copy_file(const char *srcfile, const char *dstfile, bool force)
if
(
nbytes
<
0
)
if
(
nbytes
<
0
)
{
{
int
save_errno
=
errno
;
save_errno
=
errno
;
ret
=
-
1
;
if
(
buffer
!=
NULL
)
break
;
pg_free
(
buffer
);
if
(
src_fd
!=
0
)
close
(
src_fd
);
if
(
dest_fd
!=
0
)
close
(
dest_fd
);
errno
=
save_errno
;
return
-
1
;
}
}
if
(
nbytes
==
0
)
if
(
nbytes
==
0
)
...
@@ -190,24 +171,12 @@ copy_file(const char *srcfile, const char *dstfile, bool force)
...
@@ -190,24 +171,12 @@ copy_file(const char *srcfile, const char *dstfile, bool force)
if
(
write
(
dest_fd
,
buffer
,
nbytes
)
!=
nbytes
)
if
(
write
(
dest_fd
,
buffer
,
nbytes
)
!=
nbytes
)
{
{
/* if write didn't set errno, assume problem is no disk space */
save_errno
=
errno
;
int
save_errno
=
errno
?
errno
:
ENOSPC
;
ret
=
-
1
;
break
;
if
(
buffer
!=
NULL
)
pg_free
(
buffer
);
if
(
src_fd
!=
0
)
close
(
src_fd
);
if
(
dest_fd
!=
0
)
close
(
dest_fd
);
errno
=
save_errno
;
return
-
1
;
}
}
}
}
if
(
buffer
!=
NULL
)
pg_free
(
buffer
);
pg_free
(
buffer
);
if
(
src_fd
!=
0
)
if
(
src_fd
!=
0
)
...
@@ -216,7 +185,10 @@ copy_file(const char *srcfile, const char *dstfile, bool force)
...
@@ -216,7 +185,10 @@ copy_file(const char *srcfile, const char *dstfile, bool force)
if
(
dest_fd
!=
0
)
if
(
dest_fd
!=
0
)
close
(
dest_fd
);
close
(
dest_fd
);
return
1
;
if
(
save_errno
!=
0
)
errno
=
save_errno
;
return
ret
;
}
}
#endif
#endif
...
...
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