diff options
author | Dana Robinson <43805+derobins@users.noreply.github.com> | 2020-12-16 19:50:30 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-16 19:50:30 (GMT) |
commit | a6b76a45b2c9cee3edb2474f8b97066bbcc37b62 (patch) | |
tree | 32ba13313ef0f8cfc1391b57ac43049cecf9cec6 /tools/src/misc/h5delete.c | |
parent | e4865ce716183485313238bcd6d5a82894ed5228 (diff) | |
download | hdf5-a6b76a45b2c9cee3edb2474f8b97066bbcc37b62.zip hdf5-a6b76a45b2c9cee3edb2474f8b97066bbcc37b62.tar.gz hdf5-a6b76a45b2c9cee3edb2474f8b97066bbcc37b62.tar.bz2 |
Adds h5delete tool (#187)
* Adds h5delete tool
* Fixed MANIFEST
* Added RELEASE.txt note
* Fix typo in RELEASE.txt
Diffstat (limited to 'tools/src/misc/h5delete.c')
-rw-r--r-- | tools/src/misc/h5delete.c | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/tools/src/misc/h5delete.c b/tools/src/misc/h5delete.c new file mode 100644 index 0000000..028c6c0 --- /dev/null +++ b/tools/src/misc/h5delete.c @@ -0,0 +1,71 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by The HDF Group. * + * All rights reserved. * + * * + * This file is part of HDF5. The full HDF5 copyright notice, including * + * terms governing use, modification, and redistribution, is contained in * + * the COPYING file, which can be found at the root of the source code * + * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. * + * If you do not have access to either file, you may request a copy from * + * help@hdfgroup.org. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +/* h5delete tool + * + * Deletes storage via H5Fdelete() using the VOL connector specified in the + * environment variable. + */ + +#include "H5private.h" +#include "H5Eprivate.h" +#include "H5Pprivate.h" + +static void usage(void); + +static void +usage(void) +{ + HDfprintf(stderr, "Usage: h5delete [-f] <filename>\n"); +} + +int +main(int argc, const char *argv[]) +{ + hbool_t quiet = FALSE; + const char *name = NULL; + int ret = 0; + + switch (argc) { + case 3: + if (HDstrcmp(argv[1], "-f")) { + usage(); + return EXIT_FAILURE; + } + quiet = TRUE; + name = argv[2]; + break; + case 2: + name = argv[1]; + break; + default: + usage(); + return EXIT_FAILURE; + } + + H5E_BEGIN_TRY { + /* Only uses the environment variable at this time */ + ret = (int)H5Fdelete(name, H5P_DEFAULT); + } H5E_END_TRY; + + /* The native VOL connector does not implement the H5Fdelete() call + * at this time, so try to remove the file via the POSIX remove(3) + * call on failures. + */ + if (ret < 0) + ret = HDremove(name); + + if (ret < 0 && !quiet) + HDfprintf(stderr, "Unable to delete storage at: %s\n", name); + + return ret < 0 ? EXIT_FAILURE : EXIT_SUCCESS; +} |