diff options
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/crypto_hash.c | 2 | ||||
-rw-r--r-- | src/util/crypto_rsa.c | 2 | ||||
-rw-r--r-- | src/util/disk.c | 17 | ||||
-rw-r--r-- | src/util/pseudonym.c | 4 | ||||
-rw-r--r-- | src/util/test_disk.c | 2 |
5 files changed, 20 insertions, 7 deletions
diff --git a/src/util/crypto_hash.c b/src/util/crypto_hash.c index aaf5175d7..57e37f3fd 100644 --- a/src/util/crypto_hash.c +++ b/src/util/crypto_hash.c | |||
@@ -220,7 +220,7 @@ GNUNET_CRYPTO_hash_file (enum GNUNET_SCHEDULER_Priority priority, | |||
220 | return NULL; | 220 | return NULL; |
221 | } | 221 | } |
222 | fhc->bsize = blocksize; | 222 | fhc->bsize = blocksize; |
223 | if (GNUNET_OK != GNUNET_DISK_file_size (filename, &fhc->fsize, GNUNET_NO)) | 223 | if (GNUNET_OK != GNUNET_DISK_file_size (filename, &fhc->fsize, GNUNET_NO, GNUNET_YES)) |
224 | { | 224 | { |
225 | GNUNET_free (fhc->filename); | 225 | GNUNET_free (fhc->filename); |
226 | GNUNET_free (fhc); | 226 | GNUNET_free (fhc); |
diff --git a/src/util/crypto_rsa.c b/src/util/crypto_rsa.c index ee7e5e9f8..0106f43be 100644 --- a/src/util/crypto_rsa.c +++ b/src/util/crypto_rsa.c | |||
@@ -726,7 +726,7 @@ GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename) | |||
726 | 726 | ||
727 | return NULL; | 727 | return NULL; |
728 | } | 728 | } |
729 | if (GNUNET_YES != GNUNET_DISK_file_size (filename, &fs, GNUNET_YES)) | 729 | if (GNUNET_OK != GNUNET_DISK_file_size (filename, &fs, GNUNET_YES, GNUNET_YES)) |
730 | fs = 0; | 730 | fs = 0; |
731 | if (fs < sizeof (struct GNUNET_CRYPTO_RsaPrivateKeyBinaryEncoded)) | 731 | if (fs < sizeof (struct GNUNET_CRYPTO_RsaPrivateKeyBinaryEncoded)) |
732 | { | 732 | { |
diff --git a/src/util/disk.c b/src/util/disk.c index b6b458f15..ae3ac4c41 100644 --- a/src/util/disk.c +++ b/src/util/disk.c | |||
@@ -112,6 +112,11 @@ struct GetFileSizeData | |||
112 | * GNUNET_YES if symbolic links should be included. | 112 | * GNUNET_YES if symbolic links should be included. |
113 | */ | 113 | */ |
114 | int include_sym_links; | 114 | int include_sym_links; |
115 | |||
116 | /** | ||
117 | * GNUNET_YES if mode is file-only (return total == -1 for directories). | ||
118 | */ | ||
119 | int single_file_mode; | ||
115 | }; | 120 | }; |
116 | 121 | ||
117 | 122 | ||
@@ -176,6 +181,11 @@ getSizeRec (void *cls, const char *fn) | |||
176 | return GNUNET_SYSERR; | 181 | return GNUNET_SYSERR; |
177 | } | 182 | } |
178 | #endif | 183 | #endif |
184 | if ((S_ISDIR (buf.st_mode)) && (gfsd->single_file_mode == GNUNET_YES)) | ||
185 | { | ||
186 | errno = EISDIR; | ||
187 | return GNUNET_SYSERR; | ||
188 | } | ||
179 | if ((!S_ISLNK (buf.st_mode)) || (gfsd->include_sym_links == GNUNET_YES)) | 189 | if ((!S_ISLNK (buf.st_mode)) || (gfsd->include_sym_links == GNUNET_YES)) |
180 | gfsd->total += buf.st_size; | 190 | gfsd->total += buf.st_size; |
181 | if ((S_ISDIR (buf.st_mode)) && (0 == ACCESS (fn, X_OK)) && | 191 | if ((S_ISDIR (buf.st_mode)) && (0 == ACCESS (fn, X_OK)) && |
@@ -290,11 +300,13 @@ GNUNET_DISK_file_seek (const struct GNUNET_DISK_FileHandle * h, OFF_T offset, | |||
290 | * of all sizes of files in the directory) | 300 | * of all sizes of files in the directory) |
291 | * @param includeSymLinks should symbolic links be | 301 | * @param includeSymLinks should symbolic links be |
292 | * included? | 302 | * included? |
303 | * @param singleFileMode GNUNET_YES to only get size of one file | ||
304 | * and return GNUNET_SYSERR for directories. | ||
293 | * @return GNUNET_SYSERR on error, GNUNET_OK on success | 305 | * @return GNUNET_SYSERR on error, GNUNET_OK on success |
294 | */ | 306 | */ |
295 | int | 307 | int |
296 | GNUNET_DISK_file_size (const char *filename, uint64_t * size, | 308 | GNUNET_DISK_file_size (const char *filename, uint64_t * size, |
297 | int includeSymLinks) | 309 | int includeSymLinks, int singleFileMode) |
298 | { | 310 | { |
299 | struct GetFileSizeData gfsd; | 311 | struct GetFileSizeData gfsd; |
300 | int ret; | 312 | int ret; |
@@ -302,6 +314,7 @@ GNUNET_DISK_file_size (const char *filename, uint64_t * size, | |||
302 | GNUNET_assert (size != NULL); | 314 | GNUNET_assert (size != NULL); |
303 | gfsd.total = 0; | 315 | gfsd.total = 0; |
304 | gfsd.include_sym_links = includeSymLinks; | 316 | gfsd.include_sym_links = includeSymLinks; |
317 | gfsd.single_file_mode = singleFileMode; | ||
305 | ret = getSizeRec (&gfsd, filename); | 318 | ret = getSizeRec (&gfsd, filename); |
306 | *size = gfsd.total; | 319 | *size = gfsd.total; |
307 | return ret; | 320 | return ret; |
@@ -1350,7 +1363,7 @@ GNUNET_DISK_file_copy (const char *src, const char *dst) | |||
1350 | struct GNUNET_DISK_FileHandle *in; | 1363 | struct GNUNET_DISK_FileHandle *in; |
1351 | struct GNUNET_DISK_FileHandle *out; | 1364 | struct GNUNET_DISK_FileHandle *out; |
1352 | 1365 | ||
1353 | if (GNUNET_OK != GNUNET_DISK_file_size (src, &size, GNUNET_YES)) | 1366 | if (GNUNET_OK != GNUNET_DISK_file_size (src, &size, GNUNET_YES, GNUNET_YES)) |
1354 | return GNUNET_SYSERR; | 1367 | return GNUNET_SYSERR; |
1355 | pos = 0; | 1368 | pos = 0; |
1356 | in = GNUNET_DISK_file_open (src, GNUNET_DISK_OPEN_READ, | 1369 | in = GNUNET_DISK_file_open (src, GNUNET_DISK_OPEN_READ, |
diff --git a/src/util/pseudonym.c b/src/util/pseudonym.c index c2b95832e..d2efdc98f 100644 --- a/src/util/pseudonym.c +++ b/src/util/pseudonym.c | |||
@@ -320,7 +320,7 @@ GNUNET_PSEUDONYM_name_uniquify (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
320 | 320 | ||
321 | len = 0; | 321 | len = 0; |
322 | if (0 == STAT (fn, &sbuf)) | 322 | if (0 == STAT (fn, &sbuf)) |
323 | GNUNET_break (GNUNET_OK == GNUNET_DISK_file_size (fn, &len, GNUNET_YES)); | 323 | GNUNET_break (GNUNET_OK == GNUNET_DISK_file_size (fn, &len, GNUNET_YES, GNUNET_YES)); |
324 | fh = GNUNET_DISK_file_open (fn, | 324 | fh = GNUNET_DISK_file_open (fn, |
325 | GNUNET_DISK_OPEN_CREATE | | 325 | GNUNET_DISK_OPEN_CREATE | |
326 | GNUNET_DISK_OPEN_READWRITE, | 326 | GNUNET_DISK_OPEN_READWRITE, |
@@ -475,7 +475,7 @@ GNUNET_PSEUDONYM_name_to_id (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
475 | GNUNET_assert (fn != NULL); | 475 | GNUNET_assert (fn != NULL); |
476 | 476 | ||
477 | if ((GNUNET_OK != GNUNET_DISK_file_test (fn) || | 477 | if ((GNUNET_OK != GNUNET_DISK_file_test (fn) || |
478 | (GNUNET_OK != GNUNET_DISK_file_size (fn, &len, GNUNET_YES))) || | 478 | (GNUNET_OK != GNUNET_DISK_file_size (fn, &len, GNUNET_YES, GNUNET_YES))) || |
479 | ((idx + 1) * sizeof (GNUNET_HashCode) > len)) | 479 | ((idx + 1) * sizeof (GNUNET_HashCode) > len)) |
480 | { | 480 | { |
481 | GNUNET_free (fn); | 481 | GNUNET_free (fn); |
diff --git a/src/util/test_disk.c b/src/util/test_disk.c index 546277256..149cec0b2 100644 --- a/src/util/test_disk.c +++ b/src/util/test_disk.c | |||
@@ -97,7 +97,7 @@ testOpenClose () | |||
97 | GNUNET_break (5 == GNUNET_DISK_file_write (fh, "Hello", 5)); | 97 | GNUNET_break (5 == GNUNET_DISK_file_write (fh, "Hello", 5)); |
98 | GNUNET_DISK_file_close (fh); | 98 | GNUNET_DISK_file_close (fh); |
99 | GNUNET_break (GNUNET_OK == | 99 | GNUNET_break (GNUNET_OK == |
100 | GNUNET_DISK_file_size (".testfile", &size, GNUNET_NO)); | 100 | GNUNET_DISK_file_size (".testfile", &size, GNUNET_NO, GNUNET_YES)); |
101 | if (size != 5) | 101 | if (size != 5) |
102 | return 1; | 102 | return 1; |
103 | GNUNET_break (0 == UNLINK (".testfile")); | 103 | GNUNET_break (0 == UNLINK (".testfile")); |