aboutsummaryrefslogtreecommitdiff
path: root/src/util/disk.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/disk.c')
-rw-r--r--src/util/disk.c77
1 files changed, 73 insertions, 4 deletions
diff --git a/src/util/disk.c b/src/util/disk.c
index 8fd689070..9e542a91c 100644
--- a/src/util/disk.c
+++ b/src/util/disk.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2001--2013, 2016 GNUnet e.V. 3 Copyright (C) 2001--2013, 2016, 2018 GNUnet e.V.
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -1401,13 +1401,28 @@ GNUNET_DISK_file_copy (const char *src,
1401 struct GNUNET_DISK_FileHandle *in; 1401 struct GNUNET_DISK_FileHandle *in;
1402 struct GNUNET_DISK_FileHandle *out; 1402 struct GNUNET_DISK_FileHandle *out;
1403 1403
1404 if (GNUNET_OK != GNUNET_DISK_file_size (src, &size, GNUNET_YES, GNUNET_YES)) 1404 if (GNUNET_OK !=
1405 GNUNET_DISK_file_size (src,
1406 &size,
1407 GNUNET_YES,
1408 GNUNET_YES))
1409 {
1410 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
1411 "stat",
1412 src);
1405 return GNUNET_SYSERR; 1413 return GNUNET_SYSERR;
1414 }
1406 pos = 0; 1415 pos = 0;
1407 in = GNUNET_DISK_file_open (src, GNUNET_DISK_OPEN_READ, 1416 in = GNUNET_DISK_file_open (src,
1417 GNUNET_DISK_OPEN_READ,
1408 GNUNET_DISK_PERM_NONE); 1418 GNUNET_DISK_PERM_NONE);
1409 if (!in) 1419 if (! in)
1420 {
1421 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
1422 "open",
1423 src);
1410 return GNUNET_SYSERR; 1424 return GNUNET_SYSERR;
1425 }
1411 out = 1426 out =
1412 GNUNET_DISK_file_open (dst, 1427 GNUNET_DISK_file_open (dst,
1413 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE | 1428 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE |
@@ -1418,6 +1433,9 @@ GNUNET_DISK_file_copy (const char *src,
1418 GNUNET_DISK_PERM_GROUP_WRITE); 1433 GNUNET_DISK_PERM_GROUP_WRITE);
1419 if (!out) 1434 if (!out)
1420 { 1435 {
1436 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
1437 "open",
1438 dst);
1421 GNUNET_DISK_file_close (in); 1439 GNUNET_DISK_file_close (in);
1422 return GNUNET_SYSERR; 1440 return GNUNET_SYSERR;
1423 } 1441 }
@@ -2641,4 +2659,55 @@ GNUNET_DISK_internal_file_handle_ (const struct GNUNET_DISK_FileHandle *fh,
2641 return GNUNET_OK; 2659 return GNUNET_OK;
2642} 2660}
2643 2661
2662
2663/**
2664 * Remove the directory given under @a option in
2665 * section [PATHS] in configuration under @a cfg_filename
2666 *
2667 * @param cfg_filename configuration file to parse
2668 * @param option option with the dir name to purge
2669 */
2670void
2671GNUNET_DISK_purge_cfg_dir (const char *cfg_filename,
2672 const char *option)
2673{
2674 struct GNUNET_CONFIGURATION_Handle *cfg;
2675 char *tmpname;
2676
2677 cfg = GNUNET_CONFIGURATION_create ();
2678 if (GNUNET_OK !=
2679 GNUNET_CONFIGURATION_load (cfg,
2680 cfg_filename))
2681 {
2682 GNUNET_break (0);
2683 GNUNET_CONFIGURATION_destroy (cfg);
2684 return;
2685 }
2686 if (GNUNET_OK !=
2687 GNUNET_CONFIGURATION_get_value_filename (cfg,
2688 "PATHS",
2689 option,
2690 &tmpname))
2691 {
2692 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
2693 "PATHS",
2694 option);
2695 GNUNET_CONFIGURATION_destroy (cfg);
2696 return;
2697 }
2698 GNUNET_CONFIGURATION_destroy (cfg);
2699 if (GNUNET_SYSERR ==
2700 GNUNET_DISK_directory_remove (tmpname))
2701 {
2702 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
2703 "remove",
2704 tmpname);
2705 GNUNET_free (tmpname);
2706 return;
2707 }
2708 GNUNET_free (tmpname);
2709}
2710
2711
2712
2644/* end of disk.c */ 2713/* end of disk.c */