Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 8110715

Browse files
committed
[Issue #169] review: remove slurpFileFullPath
1 parent 251e46c commit 8110715

File tree

3 files changed

+5
-77
lines changed

3 files changed

+5
-77
lines changed

src/fetch.c

Lines changed: 4 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -13,67 +13,6 @@
1313
#include <sys/stat.h>
1414
#include <unistd.h>
1515

16-
/*
17-
* Read a file into memory.
18-
* The file contents are returned in a malloc'd buffer, and *filesize
19-
* is set to the length of the file.
20-
*
21-
* The returned buffer is always zero-terminated; the size of the returned
22-
* buffer is actually *filesize + 1. That's handy when reading a text file.
23-
* This function can be used to read binary files as well, you can just
24-
* ignore the zero-terminator in that case.
25-
*
26-
*/
27-
char *
28-
slurpFileFullPath(const char *from_fullpath, size_t *filesize, bool safe, fio_location location)
29-
{
30-
int fd;
31-
char *buffer;
32-
int len;
33-
struct stat statbuf;
34-
35-
if ((fd = fio_open(from_fullpath, O_RDONLY | PG_BINARY, location)) == -1)
36-
{
37-
if (safe)
38-
return NULL;
39-
else
40-
elog(ERROR, "Could not open file \"%s\" for reading: %s",
41-
from_fullpath, strerror(errno));
42-
}
43-
44-
if (fio_fstat(fd, &statbuf) < 0)
45-
{
46-
if (safe)
47-
return NULL;
48-
else
49-
elog(ERROR, "Could not stat file \"%s\": %s",
50-
from_fullpath, strerror(errno));
51-
}
52-
53-
len = statbuf.st_size;
54-
55-
buffer = pg_malloc(len + 1);
56-
57-
if (fio_read(fd, buffer, len) != len)
58-
{
59-
if (safe)
60-
return NULL;
61-
else
62-
elog(ERROR, "Could not read file \"%s\": %s\n",
63-
from_fullpath, strerror(errno));
64-
}
65-
66-
fio_close(fd);
67-
68-
/* Zero-terminate the buffer. */
69-
buffer[len] = '\0';
70-
71-
if (filesize)
72-
*filesize = len;
73-
74-
return buffer;
75-
}
76-
7716
/*
7817
* Read a file into memory. The file to be read is <datadir>/<path>.
7918
* The file contents are returned in a malloc'd buffer, and *filesize
@@ -93,23 +32,15 @@ slurpFile(const char *datadir, const char *path, size_t *filesize, bool safe, fi
9332
struct stat statbuf;
9433
char fullpath[MAXPGPATH];
9534
int len;
96-
snprintf(fullpath, sizeof(fullpath), "%s/%s", datadir, path);
9735

98-
if (fio_access(fullpath, R_OK, location) != 0)
99-
{
100-
if (safe)
101-
return NULL;
102-
else
103-
elog(ERROR, "could not open file \"%s\" for reading: %s",
104-
fullpath, strerror(errno));
105-
}
36+
join_path_components(fullpath, datadir, path);
10637

10738
if ((fd = fio_open(fullpath, O_RDONLY | PG_BINARY, location)) == -1)
10839
{
10940
if (safe)
11041
return NULL;
11142
else
112-
elog(ERROR, "could not open file \"%s\" for reading: %s",
43+
elog(ERROR, "Could not open file \"%s\" for reading: %s",
11344
fullpath, strerror(errno));
11445
}
11546

@@ -118,7 +49,7 @@ slurpFile(const char *datadir, const char *path, size_t *filesize, bool safe, fi
11849
if (safe)
11950
return NULL;
12051
else
121-
elog(ERROR, "could not open file \"%s\" for reading: %s",
52+
elog(ERROR, "Could not stat file \"%s\": %s",
12253
fullpath, strerror(errno));
12354
}
12455

@@ -130,7 +61,7 @@ slurpFile(const char *datadir, const char *path, size_t *filesize, bool safe, fi
13061
if (safe)
13162
return NULL;
13263
else
133-
elog(ERROR, "could not read file \"%s\": %s\n",
64+
elog(ERROR, "Could not read file \"%s\": %s\n",
13465
fullpath, strerror(errno));
13566
}
13667

src/pg_probackup.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -712,9 +712,6 @@ extern char *slurpFile(const char *datadir,
712712
size_t *filesize,
713713
bool safe,
714714
fio_location location);
715-
extern char *slurpFileFullPath(const char *from_fullpath,
716-
size_t *filesize, bool safe,
717-
fio_location location);
718715
extern char *fetchFile(PGconn *conn, const char *filename, size_t *filesize);
719716

720717
/* in help.c */

src/util.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ copy_pgcontrol_file(const char *from_fullpath, fio_location from_location,
390390
char *buffer;
391391
size_t size;
392392

393-
buffer = slurpFileFullPath(from_fullpath, &size, false, from_location);
393+
buffer = slurpFile(from_fullpath, "", &size, false, from_location);
394394

395395
digestControlFile(&ControlFile, buffer, size);
396396

0 commit comments

Comments
 (0)