diff options
author | Christian Grothoff <christian@grothoff.org> | 2009-06-16 22:57:50 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2009-06-16 22:57:50 +0000 |
commit | 20945e0603fd6817a87165a9b471654130cb6d67 (patch) | |
tree | 68e9cdaeffdfb54949aaba7c469176cef4019e15 /src | |
parent | b6bda27ce9a134c78c6084393b3370bf3691f206 (diff) | |
download | gnunet-20945e0603fd6817a87165a9b471654130cb6d67.tar.gz gnunet-20945e0603fd6817a87165a9b471654130cb6d67.zip |
fixing testcases with new disk API
Diffstat (limited to 'src')
-rw-r--r-- | src/util/container_bloomfilter.c | 12 | ||||
-rw-r--r-- | src/util/crypto_hash.c | 2 | ||||
-rw-r--r-- | src/util/disk.c | 37 | ||||
-rw-r--r-- | src/util/test_pseudonym.c | 2 |
4 files changed, 34 insertions, 19 deletions
diff --git a/src/util/container_bloomfilter.c b/src/util/container_bloomfilter.c index 7eb910270..cec686795 100644 --- a/src/util/container_bloomfilter.c +++ b/src/util/container_bloomfilter.c | |||
@@ -406,10 +406,10 @@ GNUNET_CONTAINER_bloomfilter_load (const char *filename, unsigned int size, | |||
406 | /* Try to open a bloomfilter file */ | 406 | /* Try to open a bloomfilter file */ |
407 | if (filename != NULL) | 407 | if (filename != NULL) |
408 | { | 408 | { |
409 | bf->fh = GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_WRITE | 409 | bf->fh = GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_READWRITE |
410 | | GNUNET_DISK_OPEN_READ | GNUNET_DISK_OPEN_CREATE, | 410 | | GNUNET_DISK_OPEN_CREATE, |
411 | GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE); | 411 | GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE); |
412 | if (!bf->fh) | 412 | if (NULL == bf->fh) |
413 | { | 413 | { |
414 | GNUNET_free (bf); | 414 | GNUNET_free (bf); |
415 | return NULL; | 415 | return NULL; |
@@ -437,6 +437,12 @@ GNUNET_CONTAINER_bloomfilter_load (const char *filename, unsigned int size, | |||
437 | int res; | 437 | int res; |
438 | 438 | ||
439 | res = GNUNET_DISK_file_read (bf->fh, rbuff, BUFFSIZE); | 439 | res = GNUNET_DISK_file_read (bf->fh, rbuff, BUFFSIZE); |
440 | if (res == -1) | ||
441 | { | ||
442 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, | ||
443 | "read", | ||
444 | bf->filename); | ||
445 | } | ||
440 | if (res == 0) | 446 | if (res == 0) |
441 | break; /* is ok! we just did not use that many bits yet */ | 447 | break; /* is ok! we just did not use that many bits yet */ |
442 | for (i = 0; i < res; i++) | 448 | for (i = 0; i < res; i++) |
diff --git a/src/util/crypto_hash.c b/src/util/crypto_hash.c index dbb112666..0d8cdeb5c 100644 --- a/src/util/crypto_hash.c +++ b/src/util/crypto_hash.c | |||
@@ -444,7 +444,7 @@ file_hash_finish (struct FileHashContext *fhc, const GNUNET_HashCode * res) | |||
444 | fhc->callback (fhc->callback_cls, res); | 444 | fhc->callback (fhc->callback_cls, res); |
445 | GNUNET_free (fhc->filename); | 445 | GNUNET_free (fhc->filename); |
446 | if (!GNUNET_DISK_handle_invalid (fhc->fh)) | 446 | if (!GNUNET_DISK_handle_invalid (fhc->fh)) |
447 | GNUNET_break (0 == GNUNET_DISK_file_close (&fhc->fh)); | 447 | GNUNET_break (GNUNET_OK == GNUNET_DISK_file_close (&fhc->fh)); |
448 | GNUNET_free (fhc); /* also frees fhc->buffer */ | 448 | GNUNET_free (fhc); /* also frees fhc->buffer */ |
449 | } | 449 | } |
450 | 450 | ||
diff --git a/src/util/disk.c b/src/util/disk.c index 011bd8a8d..df6e5df8a 100644 --- a/src/util/disk.c +++ b/src/util/disk.c | |||
@@ -533,8 +533,10 @@ GNUNET_DISK_fn_write (const char * const fn, const void *buffer, | |||
533 | struct GNUNET_IO_Handle *fh; | 533 | struct GNUNET_IO_Handle *fh; |
534 | int ret; | 534 | int ret; |
535 | 535 | ||
536 | fh = GNUNET_DISK_file_open (fn, GNUNET_DISK_OPEN_WRITE | 536 | fh = GNUNET_DISK_file_open (fn, |
537 | | GNUNET_DISK_OPEN_CREATE, mode); | 537 | GNUNET_DISK_OPEN_WRITE |
538 | | GNUNET_DISK_OPEN_TRUNCATE | ||
539 | | GNUNET_DISK_OPEN_CREATE, mode); | ||
538 | if (!fh) | 540 | if (!fh) |
539 | return GNUNET_SYSERR; | 541 | return GNUNET_SYSERR; |
540 | ret = (n == GNUNET_DISK_file_write (fh, buffer, n)) ? GNUNET_OK : GNUNET_SYSERR; | 542 | ret = (n == GNUNET_DISK_file_write (fh, buffer, n)) ? GNUNET_OK : GNUNET_SYSERR; |
@@ -844,9 +846,9 @@ GNUNET_DISK_file_copy (const char *src, const char *dst) | |||
844 | if (!in) | 846 | if (!in) |
845 | return GNUNET_SYSERR; | 847 | return GNUNET_SYSERR; |
846 | out = GNUNET_DISK_file_open (dst, GNUNET_DISK_OPEN_WRITE | 848 | out = GNUNET_DISK_file_open (dst, GNUNET_DISK_OPEN_WRITE |
847 | | GNUNET_DISK_OPEN_CREATE | GNUNET_DISK_OPEN_FAILIFEXISTS, | 849 | | GNUNET_DISK_OPEN_CREATE | GNUNET_DISK_OPEN_FAILIFEXISTS, |
848 | GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE | 850 | GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE |
849 | | GNUNET_DISK_PERM_GROUP_READ | GNUNET_DISK_PERM_GROUP_WRITE); | 851 | | GNUNET_DISK_PERM_GROUP_READ | GNUNET_DISK_PERM_GROUP_WRITE); |
850 | if (!out) | 852 | if (!out) |
851 | { | 853 | { |
852 | GNUNET_DISK_file_close (&in); | 854 | GNUNET_DISK_file_close (&in); |
@@ -990,14 +992,23 @@ GNUNET_DISK_file_open (const char *fn, int flags, ...) | |||
990 | 992 | ||
991 | #ifndef MINGW | 993 | #ifndef MINGW |
992 | oflags = 0; | 994 | oflags = 0; |
993 | if (flags & GNUNET_DISK_OPEN_READ) | 995 | if (GNUNET_DISK_OPEN_READWRITE == (flags & GNUNET_DISK_OPEN_READWRITE)) |
996 | oflags = O_RDWR; /* note: O_RDWR is NOT always O_RDONLY | O_WRONLY */ | ||
997 | else if (flags & GNUNET_DISK_OPEN_READ) | ||
994 | oflags = O_RDONLY; | 998 | oflags = O_RDONLY; |
995 | if (flags & GNUNET_DISK_OPEN_WRITE) | 999 | else if (flags & GNUNET_DISK_OPEN_WRITE) |
996 | oflags |= O_WRONLY; | 1000 | oflags = O_WRONLY; |
1001 | else | ||
1002 | { | ||
1003 | GNUNET_break (0); | ||
1004 | return NULL; | ||
1005 | } | ||
997 | if (flags & GNUNET_DISK_OPEN_FAILIFEXISTS) | 1006 | if (flags & GNUNET_DISK_OPEN_FAILIFEXISTS) |
998 | oflags |= (O_CREAT & O_EXCL); | 1007 | oflags |= (O_CREAT & O_EXCL); |
999 | if (flags & GNUNET_DISK_OPEN_TRUNCATE) | 1008 | if (flags & GNUNET_DISK_OPEN_TRUNCATE) |
1000 | oflags |= O_TRUNC; | 1009 | oflags |= O_TRUNC; |
1010 | if (flags & GNUNET_DISK_OPEN_APPEND) | ||
1011 | oflags |= O_APPEND; | ||
1001 | if (flags & GNUNET_DISK_OPEN_CREATE) | 1012 | if (flags & GNUNET_DISK_OPEN_CREATE) |
1002 | { | 1013 | { |
1003 | int perm; | 1014 | int perm; |
@@ -1011,26 +1022,24 @@ GNUNET_DISK_file_open (const char *fn, int flags, ...) | |||
1011 | 1022 | ||
1012 | mode = 0; | 1023 | mode = 0; |
1013 | if (perm & GNUNET_DISK_PERM_USER_READ) | 1024 | if (perm & GNUNET_DISK_PERM_USER_READ) |
1014 | mode = S_IRUSR; | 1025 | mode |= S_IRUSR; |
1015 | if (perm & GNUNET_DISK_PERM_USER_WRITE) | 1026 | if (perm & GNUNET_DISK_PERM_USER_WRITE) |
1016 | mode |= S_IWUSR; | 1027 | mode |= S_IWUSR; |
1017 | if (perm & GNUNET_DISK_PERM_USER_EXEC) | 1028 | if (perm & GNUNET_DISK_PERM_USER_EXEC) |
1018 | mode |= S_IXUSR; | 1029 | mode |= S_IXUSR; |
1019 | if (perm & GNUNET_DISK_PERM_GROUP_READ) | 1030 | if (perm & GNUNET_DISK_PERM_GROUP_READ) |
1020 | mode = S_IRGRP; | 1031 | mode |= S_IRGRP; |
1021 | if (perm & GNUNET_DISK_PERM_GROUP_WRITE) | 1032 | if (perm & GNUNET_DISK_PERM_GROUP_WRITE) |
1022 | mode |= S_IWGRP; | 1033 | mode |= S_IWGRP; |
1023 | if (perm & GNUNET_DISK_PERM_GROUP_EXEC) | 1034 | if (perm & GNUNET_DISK_PERM_GROUP_EXEC) |
1024 | mode |= S_IXGRP; | 1035 | mode |= S_IXGRP; |
1025 | if (perm & GNUNET_DISK_PERM_OTHER_READ) | 1036 | if (perm & GNUNET_DISK_PERM_OTHER_READ) |
1026 | mode = S_IROTH; | 1037 | mode |= S_IROTH; |
1027 | if (perm & GNUNET_DISK_PERM_OTHER_WRITE) | 1038 | if (perm & GNUNET_DISK_PERM_OTHER_WRITE) |
1028 | mode |= S_IWOTH; | 1039 | mode |= S_IWOTH; |
1029 | if (perm & GNUNET_DISK_PERM_OTHER_EXEC) | 1040 | if (perm & GNUNET_DISK_PERM_OTHER_EXEC) |
1030 | mode |= S_IXOTH; | 1041 | mode |= S_IXOTH; |
1031 | } | 1042 | } |
1032 | if (flags & GNUNET_DISK_OPEN_APPEND) | ||
1033 | oflags = O_APPEND; | ||
1034 | 1043 | ||
1035 | fd = open (expfn, oflags | O_LARGEFILE, mode); | 1044 | fd = open (expfn, oflags | O_LARGEFILE, mode); |
1036 | if (fd == -1) | 1045 | if (fd == -1) |
@@ -1074,7 +1083,7 @@ GNUNET_DISK_file_open (const char *fn, int flags, ...) | |||
1074 | } | 1083 | } |
1075 | #endif | 1084 | #endif |
1076 | 1085 | ||
1077 | ret = (struct GNUNET_IO_Handle *) GNUNET_malloc(sizeof(struct GNUNET_IO_Handle)); | 1086 | ret = GNUNET_malloc(sizeof(struct GNUNET_IO_Handle)); |
1078 | #ifdef MINGW | 1087 | #ifdef MINGW |
1079 | ret->h = h; | 1088 | ret->h = h; |
1080 | #else | 1089 | #else |
diff --git a/src/util/test_pseudonym.c b/src/util/test_pseudonym.c index 6d31c8a07..dd6cf680d 100644 --- a/src/util/test_pseudonym.c +++ b/src/util/test_pseudonym.c | |||
@@ -81,7 +81,7 @@ main (int argc, char *argv[]) | |||
81 | char *name2; | 81 | char *name2; |
82 | int notiCount; | 82 | int notiCount; |
83 | 83 | ||
84 | GNUNET_log_setup ("test-psuedonym", "WARNING", NULL); | 84 | GNUNET_log_setup ("test-pseudonym", "WARNING", NULL); |
85 | ok = GNUNET_YES; | 85 | ok = GNUNET_YES; |
86 | GNUNET_CRYPTO_random_disable_entropy_gathering (); | 86 | GNUNET_CRYPTO_random_disable_entropy_gathering (); |
87 | GNUNET_DISK_directory_remove ("/tmp/gnunet-pseudonym-test"); | 87 | GNUNET_DISK_directory_remove ("/tmp/gnunet-pseudonym-test"); |