From d4ffe9082fa632d5696611dc5977852cc6397bce Mon Sep 17 00:00:00 2001 From: Gabor X Toth <*@tg-x.net> Date: Wed, 27 Jan 2016 20:45:36 +0000 Subject: [PATCH] social: save file --- src/social/gnunet-service-social.c | 28 ++++++++++++++++++++++------ src/social/test_social.c | 22 +++++++++++----------- 2 files changed, 33 insertions(+), 17 deletions(-) diff --git a/src/social/gnunet-service-social.c b/src/social/gnunet-service-social.c index 85679c63c..df9f2a395 100644 --- a/src/social/gnunet-service-social.c +++ b/src/social/gnunet-service-social.c @@ -914,7 +914,16 @@ place_recv_save_method (void *cls, /* save if does not already exist */ if (GNUNET_YES != GNUNET_DISK_file_test (filename)) { - plc->file_save = GNUNET_YES; + if (0 == GNUNET_DISK_fn_write (filename, NULL, 0, + GNUNET_DISK_PERM_USER_READ + | GNUNET_DISK_PERM_USER_WRITE)) + { + plc->file_save = GNUNET_YES; + } + else + { + GNUNET_break (0); + } } GNUNET_free (filename); } @@ -945,13 +954,20 @@ place_recv_save_data (void *cls, GNUNET_DISK_directory_create_for_file (filename); struct GNUNET_DISK_FileHandle * fh = GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_WRITE, - GNUNET_DISK_PERM_USER_READ - | GNUNET_DISK_PERM_USER_WRITE); + GNUNET_DISK_PERM_NONE); GNUNET_free (filename); - GNUNET_DISK_file_seek (fh, plc->file_offset, GNUNET_DISK_SEEK_SET); - GNUNET_DISK_file_write (fh, data, data_size); - GNUNET_DISK_file_close (fh); + if (NULL != fh) + { + GNUNET_DISK_file_seek (fh, plc->file_offset, GNUNET_DISK_SEEK_SET); + GNUNET_DISK_file_write (fh, data, data_size); + GNUNET_DISK_file_close (fh); + } + else + { + GNUNET_break (0); + } + plc->file_offset += data_size; } diff --git a/src/social/test_social.c b/src/social/test_social.c index d2eed64d6..2e9b270b6 100644 --- a/src/social/test_social.c +++ b/src/social/test_social.c @@ -300,7 +300,7 @@ notify_data (void *cls, uint16_t *data_size, void *data) return GNUNET_YES; } - uint16_t size = strlen (tmit->data[tmit->n]) + 1; + uint16_t size = strlen (tmit->data[tmit->n]); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmit notify data: %u bytes available, " "processing fragment %u/%u (size %u).\n", @@ -932,10 +932,10 @@ guest_talk () "_bar_foo", DATA2ARG ("one two three")); GNUNET_PSYC_env_add (tmit.env, GNUNET_PSYC_OP_ASSIGN, "_bar_baz", DATA2ARG ("four five")); - tmit.data[0] = "zzz xxx yyy"; - tmit.data[1] = "zyx wvu tsr qpo"; + tmit.data[0] = "zzz xxx yyy "; + tmit.data[1] = "zyx wvu tsr qpo.\n"; tmit.data_delay[1] = 1; - tmit.data[2] = "testing ten nine eight"; + tmit.data[2] = "testing ten nine eight.\n"; tmit.data_count = 3; tmit.guest_talk @@ -961,11 +961,11 @@ host_announce () "_foo_bar", DATA2ARG ("foo bar")); GNUNET_PSYC_env_add (tmit.env, GNUNET_PSYC_OP_ASSIGN, "_foo_bar_baz", DATA2ARG ("foo bar baz")); - tmit.data[0] = "aaa bbb ccc"; - tmit.data[1] = "abc def ghi jkl"; + tmit.data[0] = "aaa bbb ccc "; + tmit.data[1] = "abc def ghi jkl.\n"; tmit.data_delay[1] = 1; - tmit.data[2] = "testing one two three"; - tmit.data[3] = "four five"; + tmit.data[2] = "testing one two three "; + tmit.data[3] = "four five.\n"; tmit.data_count = 4; tmit.host_ann @@ -995,9 +995,9 @@ host_announce2 () "_foo2_bar", DATA2ARG ("FOO BAR")); GNUNET_PSYC_env_add (tmit.env, GNUNET_PSYC_OP_ASSIGN, "_foo2_bar", DATA2ARG ("FOO BAR BAZ")); - tmit.data[0] = "AAA BBB CCC"; - tmit.data[1] = "ABC DEF GHI JKL"; - tmit.data[2] = "TESTING ONE TWO THREE"; + tmit.data[0] = "AAA BBB CCC "; + tmit.data[1] = "ABC DEF GHI JKL.\n"; + tmit.data[2] = "TESTING ONE TWO THREE.\n"; tmit.data_count = 3; tmit.host_ann -- 2.25.1