diff options
Diffstat (limited to 'src/util/disk.c')
-rw-r--r-- | src/util/disk.c | 17 |
1 files changed, 15 insertions, 2 deletions
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, |