Skip to content

Commit c8be423

Browse files
author
王平10304955
committed
Extending gpfdist in Cloudberry Database to Support
SFTP Protocol for Data Ingestion -- add LIBSSH2 macro ADD LIBSSH2 macro Label the SFTP-related code to indicate its characteristics.
1 parent c302784 commit c8be423

3 files changed

Lines changed: 25 additions & 11 deletions

File tree

src/backend/utils/misc/fstream/fstream.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,7 +1011,7 @@ fstream_open(const char *path, const struct fstream_options *options,
10111011
struct gpfxdist_t* transform = (i == 0) ? options->transform : NULL;
10121012

10131013
gfile_close(&fs->fd);
1014-
1014+
#ifdef LIBSSH2
10151015
if (is_sftp)
10161016
{
10171017
if (gfile_open_sftp(&fs->fd, fs->glob.gl_pathv[i], fs->glob.gl_username[i], fs->glob.gl_passwd[i],
@@ -1022,6 +1022,7 @@ fstream_open(const char *path, const struct fstream_options *options,
10221022
return 0;
10231023
}
10241024
}
1025+
#endif
10251026
else
10261027
{
10271028
if (gfile_open(&fs->fd, fs->glob.gl_pathv[i], gfile_open_flags(options->forwrite, options->usesync),
@@ -1082,7 +1083,7 @@ static int nextFile(fstream_t*fs)
10821083
if (fs->fidx < fs->glob.gl_pathc)
10831084
{
10841085
fs->skip_header_line = fs->options.header;
1085-
1086+
#ifdef LIBSSH2
10861087
if (fs->fd.is_sftp)
10871088
{
10881089
if (gfile_open_sftp(&fs->fd, fs->glob.gl_pathv[fs->fidx], fs->glob.gl_username[fs->fidx], fs->glob.gl_passwd[fs->fidx],
@@ -1094,7 +1095,7 @@ static int nextFile(fstream_t*fs)
10941095
return 1;
10951096
}
10961097
}
1097-
1098+
#endif
10981099
else
10991100
{
11001101
if (gfile_open(&fs->fd, fs->glob.gl_pathv[fs->fidx], GFILE_OPEN_FOR_READ,
@@ -1105,7 +1106,7 @@ static int nextFile(fstream_t*fs)
11051106
fs->ferror = "unable to open file";
11061107
return 1;
11071108
}
1108-
}
1109+
}
11091110
}
11101111

11111112
return 0;

src/backend/utils/misc/fstream/gfile.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,11 @@
4040
#include <sys/file.h> /* for flock */
4141
#include <unistd.h>
4242

43+
#ifdef LIBSSH2
4344
#include <libssh2.h>
4445
#include <libssh2_sftp.h>
46+
#endif
47+
4548
#include <arpa/inet.h>
4649
#include <net/if.h>
4750

@@ -151,6 +154,7 @@ writewinpipe(gfile_t* fd, void* ptr, size_t size)
151154
return i;
152155
}
153156

157+
#ifdef LIBSSH2
154158
static ssize_t
155159
sftp_read(gfile_t *fd, void *ptr, size_t size)
156160
{
@@ -189,6 +193,7 @@ sftp_close(gfile_t *fd)
189193
libssh2_exit();
190194
return 0;
191195
}
196+
#endif
192197

193198
#ifdef HAVE_LIBBZ2
194199
static void *
@@ -1378,11 +1383,12 @@ gfile_close(gfile_t*fd)
13781383
{
13791384
fd->close(fd);
13801385
}
1381-
1386+
#ifdef LIBSSH2
13821387
if (fd->is_sftp)
13831388
{
13841389
sftp_close(fd);
13851390
}
1391+
#endif
13861392
else
13871393
{
13881394
if (fd->is_win_pipe)
@@ -1410,6 +1416,7 @@ gfile_close(gfile_t*fd)
14101416
return ret;
14111417
}
14121418

1419+
#ifdef LIBSSH2
14131420
int gfile_open_sftp(gfile_t *fd, const char *fpath, const char *sftp_uname, const char *sftp_passwd, const char *sftp_hostaddr,
14141421
const char *sftp_port, int flags, int *response_code, const char **response_string, struct gpfxdist_t *transform)
14151422
{
@@ -1497,6 +1504,7 @@ int gfile_open_sftp(gfile_t *fd, const char *fpath, const char *sftp_uname, cons
14971504

14981505
return 1;
14991506
}
1507+
#endif
15001508

15011509
ssize_t
15021510
gfile_read(gfile_t *fd, void *ptr, size_t len)
@@ -1548,7 +1556,7 @@ off_t gfile_get_compressed_position(gfile_t *fd)
15481556
return fd->compressed_position;
15491557
}
15501558

1551-
1559+
#ifdef LIBSSH2
15521560
int sftp_open(gfile_t *fd, const char *fpath, const char *sftp_uname, const char *sftp_passwd, const char *sftp_hostaddr,
15531561
const char *sftp_port)
15541562
{
@@ -1651,3 +1659,4 @@ void sftp_free(gfile_t *fd)
16511659
fd->sock = -1;
16521660
libssh2_exit();
16531661
}
1662+
#endif

src/include/fstream/gfile.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
#include <zstd.h>
1313
#endif
1414

15+
#ifdef LIBSSH2
16+
#include <libssh2.h>
17+
#include <libssh2_sftp.h>
18+
#endif
19+
1520
#ifdef WIN32
1621
#include <windows.h>
1722
#endif
@@ -26,9 +31,6 @@ typedef _int64 ssize_t;
2631

2732
#include "c.h"
2833

29-
#include <libssh2.h>
30-
#include <libssh2_sftp.h>
31-
3234
#ifdef WIN32
3335
typedef BOOL bool_t;
3436
#else
@@ -116,8 +118,6 @@ int gfile_open_flags(int writing, int usesync);
116118
#define GFILE_OPEN_FOR_WRITE_SYNC 2
117119

118120
int gfile_open(gfile_t* fd, const char* fpath, int flags, int* response_code, const char** response_string, struct gpfxdist_t* transform);
119-
int gfile_open_sftp(gfile_t *fd, const char *fpath, const char *sftp_uname, const char *sftp_passwd, const char *sftp_hostaddr,
120-
const char *sftp_port, int flags, int *response_code, const char **response_string, struct gpfxdist_t *transform);
121121
int gfile_close(gfile_t*fd);
122122
off_t gfile_get_compressed_size(gfile_t*fd);
123123
off_t gfile_get_compressed_position(gfile_t*fd);
@@ -127,7 +127,11 @@ void gfile_printf_then_putc_newline(const char*format,...) pg_attribute_printf(1
127127
void*gfile_malloc(size_t size);
128128
void gfile_free(void*a);
129129

130+
#ifdef LIBSSH2
131+
int gfile_open_sftp(gfile_t *fd, const char *fpath, const char *sftp_uname, const char *sftp_passwd, const char *sftp_hostaddr,
132+
const char *sftp_port, int flags, int *response_code, const char **response_string, struct gpfxdist_t *transform);
130133
extern int sftp_open(gfile_t *fd, const char *fpath, const char *sftp_uname, const char *sftp_passwd, const char *sftp_hostaddr,
131134
const char *sftp_port);
132135
extern void sftp_free(gfile_t *fd);
133136
#endif
137+
#endif

0 commit comments

Comments
 (0)