Skip to content

Commit 5990ea9

Browse files
committed
Improved cloudsync_payload_load
1 parent eadf243 commit 5990ea9

File tree

4 files changed

+7
-5
lines changed

4 files changed

+7
-5
lines changed

src/cloudsync.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2348,14 +2348,15 @@ void cloudsync_payload_load (sqlite3_context *context, int argc, sqlite3_value *
23482348
// retrieve full path to file
23492349
const char *path = (const char *)sqlite3_value_text(argv[0]);
23502350

2351-
size_t payload_size = 0;
2351+
sqlite3_int64 payload_size = 0;
23522352
char *payload = file_read(path, &payload_size);
23532353
if (!payload) {
23542354
if (payload_size == -1) sqlite3_result_error(context, "Unable to read payload from file path.", -1);
2355+
if (payload) cloudsync_memory_free(payload);
23552356
return;
23562357
}
23572358

2358-
int nrows = cloudsync_payload_apply (context, payload, (int)payload_size);
2359+
int nrows = (payload_size) ? cloudsync_payload_apply (context, payload, (int)payload_size) : 0;
23592360
if (payload) cloudsync_memory_free(payload);
23602361

23612362
// returns number of applied rows

src/cloudsync.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
extern "C" {
2121
#endif
2222

23-
#define CLOUDSYNC_VERSION "0.8.35"
23+
#define CLOUDSYNC_VERSION "0.8.36"
2424

2525
int sqlite3_cloudsync_init (sqlite3 *db, char **pzErrMsg, const sqlite3_api_routines *pApi);
2626

src/utils.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ static bool file_read_all (int fd, char *buf, size_t n) {
322322
return true;
323323
}
324324

325-
char *file_read (const char *path, size_t *len) {
325+
char *file_read (const char *path, sqlite3_int64 *len) {
326326
int fd = -1;
327327
char *buffer = NULL;
328328

@@ -359,6 +359,7 @@ char *file_read (const char *path, size_t *len) {
359359
return buffer;
360360

361361
abort_read:
362+
//fprintf(stderr, "file_read: failed to read '%s': %s\n", path, strerror(errno));
362363
if (len) *len = -1;
363364
if (buffer) cloudsync_memory_free(buffer);
364365
if (fd >= 0) file_close(fd);

src/utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ void cloudsync_rowid_decode (sqlite3_int64 rowid, sqlite3_int64 *db_version, sql
151151
// available only on Desktop OS
152152
#ifdef CLOUDSYNC_DESKTOP_OS
153153
bool file_delete (const char *path);
154-
char *file_read (const char *path, size_t *len);
154+
char *file_read (const char *path, sqlite3_int64 *len);
155155
bool file_write (const char *path, const char *buffer, size_t len);
156156
#endif
157157

0 commit comments

Comments
 (0)