diff options
-rw-r--r-- | src/fs/fs_api.c | 33 | ||||
-rw-r--r-- | src/fs/fs_publish.c | 2 | ||||
-rw-r--r-- | src/fs/fs_tree.c | 1 |
3 files changed, 29 insertions, 7 deletions
diff --git a/src/fs/fs_api.c b/src/fs/fs_api.c index 42bfaed3c..e2a3b6019 100644 --- a/src/fs/fs_api.c +++ b/src/fs/fs_api.c | |||
@@ -291,7 +291,11 @@ struct FileInfo | |||
291 | * @param cls closure (points to the file information) | 291 | * @param cls closure (points to the file information) |
292 | * @param offset offset to read from; it is possible | 292 | * @param offset offset to read from; it is possible |
293 | * that the caller might need to go backwards | 293 | * that the caller might need to go backwards |
294 | * a bit at times | 294 | * a bit at times; set to UINT64_MAX to tell |
295 | * the reader that we won't be reading for a while | ||
296 | * (used to close the file descriptor but NOT fully | ||
297 | * clean up the reader's state); in this case, | ||
298 | * a value of '0' for max should be ignored | ||
295 | * @param max maximum number of bytes that should be | 299 | * @param max maximum number of bytes that should be |
296 | * copied to buf; readers are not allowed | 300 | * copied to buf; readers are not allowed |
297 | * to provide less data unless there is an error; | 301 | * to provide less data unless there is an error; |
@@ -308,20 +312,29 @@ GNUNET_FS_data_reader_file_ (void *cls, uint64_t offset, size_t max, void *buf, | |||
308 | struct FileInfo *fi = cls; | 312 | struct FileInfo *fi = cls; |
309 | ssize_t ret; | 313 | ssize_t ret; |
310 | 314 | ||
311 | if (max == 0) | 315 | if (UINT64_MAX == offset) |
316 | { | ||
317 | if (NULL != fi->fd) | ||
318 | { | ||
319 | GNUNET_DISK_file_close (fi->fd); | ||
320 | fi->fd = NULL; | ||
321 | } | ||
322 | return 0; | ||
323 | } | ||
324 | if (0 == max) | ||
312 | { | 325 | { |
313 | if (fi->fd != NULL) | 326 | if (NULL != fi->fd) |
314 | GNUNET_DISK_file_close (fi->fd); | 327 | GNUNET_DISK_file_close (fi->fd); |
315 | GNUNET_free (fi->filename); | 328 | GNUNET_free (fi->filename); |
316 | GNUNET_free (fi); | 329 | GNUNET_free (fi); |
317 | return 0; | 330 | return 0; |
318 | } | 331 | } |
319 | if (fi->fd == NULL) | 332 | if (NULL == fi->fd) |
320 | { | 333 | { |
321 | fi->fd = | 334 | fi->fd = |
322 | GNUNET_DISK_file_open (fi->filename, GNUNET_DISK_OPEN_READ, | 335 | GNUNET_DISK_file_open (fi->filename, GNUNET_DISK_OPEN_READ, |
323 | GNUNET_DISK_PERM_NONE); | 336 | GNUNET_DISK_PERM_NONE); |
324 | if (fi->fd == NULL) | 337 | if (NULL == fi->fd) |
325 | { | 338 | { |
326 | GNUNET_asprintf (emsg, _("Could not open file `%s': %s"), fi->filename, | 339 | GNUNET_asprintf (emsg, _("Could not open file `%s': %s"), fi->filename, |
327 | STRERROR (errno)); | 340 | STRERROR (errno)); |
@@ -330,7 +343,7 @@ GNUNET_FS_data_reader_file_ (void *cls, uint64_t offset, size_t max, void *buf, | |||
330 | } | 343 | } |
331 | GNUNET_DISK_file_seek (fi->fd, offset, GNUNET_DISK_SEEK_SET); | 344 | GNUNET_DISK_file_seek (fi->fd, offset, GNUNET_DISK_SEEK_SET); |
332 | ret = GNUNET_DISK_file_read (fi->fd, buf, max); | 345 | ret = GNUNET_DISK_file_read (fi->fd, buf, max); |
333 | if (ret == -1) | 346 | if (-1 == ret) |
334 | { | 347 | { |
335 | GNUNET_asprintf (emsg, _("Could not read file `%s': %s"), fi->filename, | 348 | GNUNET_asprintf (emsg, _("Could not read file `%s': %s"), fi->filename, |
336 | STRERROR (errno)); | 349 | STRERROR (errno)); |
@@ -374,7 +387,11 @@ GNUNET_FS_make_file_reader_context_ (const char *filename) | |||
374 | * @param cls closure (points to the buffer) | 387 | * @param cls closure (points to the buffer) |
375 | * @param offset offset to read from; it is possible | 388 | * @param offset offset to read from; it is possible |
376 | * that the caller might need to go backwards | 389 | * that the caller might need to go backwards |
377 | * a bit at times | 390 | * a bit at times; set to UINT64_MAX to tell |
391 | * the reader that we won't be reading for a while | ||
392 | * (used to close the file descriptor but NOT fully | ||
393 | * clean up the reader's state); in this case, | ||
394 | * a value of '0' for max should be ignored | ||
378 | * @param max maximum number of bytes that should be | 395 | * @param max maximum number of bytes that should be |
379 | * copied to buf; readers are not allowed | 396 | * copied to buf; readers are not allowed |
380 | * to provide less data unless there is an error; | 397 | * to provide less data unless there is an error; |
@@ -390,6 +407,8 @@ GNUNET_FS_data_reader_copy_ (void *cls, uint64_t offset, size_t max, void *buf, | |||
390 | { | 407 | { |
391 | char *data = cls; | 408 | char *data = cls; |
392 | 409 | ||
410 | if (UINT64_MAX == offset) | ||
411 | return 0; | ||
393 | if (max == 0) | 412 | if (max == 0) |
394 | { | 413 | { |
395 | GNUNET_free_non_null (data); | 414 | GNUNET_free_non_null (data); |
diff --git a/src/fs/fs_publish.c b/src/fs/fs_publish.c index b3f6415c8..e0a6f046a 100644 --- a/src/fs/fs_publish.c +++ b/src/fs/fs_publish.c | |||
@@ -355,6 +355,8 @@ block_reader (void *cls, uint64_t offset, size_t max, void *buf, char **emsg) | |||
355 | } | 355 | } |
356 | else | 356 | else |
357 | { | 357 | { |
358 | if (UINT64_MAX == offset) | ||
359 | return p->data.file.reader (p->data.file.reader_cls, offset, 0, NULL, NULL); | ||
358 | pt_size = GNUNET_MIN (max, p->data.file.file_size - offset); | 360 | pt_size = GNUNET_MIN (max, p->data.file.file_size - offset); |
359 | if (pt_size == 0) | 361 | if (pt_size == 0) |
360 | return 0; /* calling reader with pt_size==0 | 362 | return 0; /* calling reader with pt_size==0 |
diff --git a/src/fs/fs_tree.c b/src/fs/fs_tree.c index 2bdf8a062..30cdded67 100644 --- a/src/fs/fs_tree.c +++ b/src/fs/fs_tree.c | |||
@@ -429,6 +429,7 @@ void | |||
429 | GNUNET_FS_tree_encoder_finish (struct GNUNET_FS_TreeEncoder *te, | 429 | GNUNET_FS_tree_encoder_finish (struct GNUNET_FS_TreeEncoder *te, |
430 | struct GNUNET_FS_Uri **uri, char **emsg) | 430 | struct GNUNET_FS_Uri **uri, char **emsg) |
431 | { | 431 | { |
432 | (void) te->reader (te->cls, UINT64_MAX, 0, 0, NULL); | ||
432 | GNUNET_assert (GNUNET_NO == te->in_next); | 433 | GNUNET_assert (GNUNET_NO == te->in_next); |
433 | if (uri != NULL) | 434 | if (uri != NULL) |
434 | *uri = te->uri; | 435 | *uri = te->uri; |