aboutsummaryrefslogtreecommitdiff
path: root/src/fs/fs_api.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-03-24 19:13:25 +0000
committerChristian Grothoff <christian@grothoff.org>2012-03-24 19:13:25 +0000
commite8a3316b8b361bff25b1fd09509e57abef1ef549 (patch)
tree0b43aabb5c7575dee538eeb0f34de45c470b2390 /src/fs/fs_api.c
parentb78e4f20e152830ca627ffc4735621f9b5b6929d (diff)
downloadgnunet-e8a3316b8b361bff25b1fd09509e57abef1ef549.tar.gz
gnunet-e8a3316b8b361bff25b1fd09509e57abef1ef549.zip
fixing issue with gnunet-publish not closing files early enough when publishing directories with more than FD_MAX files (#2239)
Diffstat (limited to 'src/fs/fs_api.c')
-rw-r--r--src/fs/fs_api.c33
1 files changed, 26 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);