summaryrefslogtreecommitdiffstats
path: root/tools/src
diff options
context:
space:
mode:
authorDana Robinson <43805+derobins@users.noreply.github.com>2021-03-22 16:32:40 (GMT)
committerGitHub <noreply@github.com>2021-03-22 16:32:40 (GMT)
commit60e14b826a22452934f7057196c1ce4d0054d97a (patch)
treecb33f8b4d8840a7d0e2c653bde8e73020837624d /tools/src
parent05bc1905cb37d145c29c036bacb1caac63c7f0c9 (diff)
downloadhdf5-60e14b826a22452934f7057196c1ce4d0054d97a.zip
hdf5-60e14b826a22452934f7057196c1ce4d0054d97a.tar.gz
hdf5-60e14b826a22452934f7057196c1ce4d0054d97a.tar.bz2
File locks now work on Windows (#480)
* File locks now work on Windows Uses LockFileEx() and UnlockFileEx(). Fixes HDFFV-10191 (partial). * Committing clang-format changes * Committing clang-format changes * Fixes commenting in h5repack * Reworks H5Fis_accessible() H5Fis_accessible() created a new file handle and attempted to read through it, which will fail when a file has been opened with an exclusive lock on operating systems that have mandatory locks. This change uses the same scheme we use in H5Fopen() to check if the file is already open and only tries to read the file signature if the file has not already been opened. Also adds a test for this behavior. * Committing clang-format changes * Trivial change to force github to run actions Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
Diffstat (limited to 'tools/src')
-rw-r--r--tools/src/h5repack/h5repack_copy.c67
1 files changed, 46 insertions, 21 deletions
diff --git a/tools/src/h5repack/h5repack_copy.c b/tools/src/h5repack/h5repack_copy.c
index 7e05a5a..536de69 100644
--- a/tools/src/h5repack/h5repack_copy.c
+++ b/tools/src/h5repack/h5repack_copy.c
@@ -305,14 +305,6 @@ copy_objects(const char *fnamein, const char *fnameout, pack_opt_t *options)
H5TOOLS_GOTO_ERROR((-1), "H5Fcreate could not create file <%s>:", fnameout);
/*-------------------------------------------------------------------------
- * write a new user block if requested
- *-------------------------------------------------------------------------
- */
- if (options->ublock_size > 0)
- if (copy_user_block(options->ublock_filename, fnameout, options->ublock_size) < 0)
- H5TOOLS_GOTO_ERROR((-1), "Could not copy user block. Exiting...");
-
- /*-------------------------------------------------------------------------
* get list of objects
*-------------------------------------------------------------------------
*/
@@ -346,27 +338,60 @@ copy_objects(const char *fnamein, const char *fnameout, pack_opt_t *options)
}
/*-------------------------------------------------------------------------
- * write only the input file user block if there is no user block file input
+ * Close the file and everything in it so the lock is removed
+ *-------------------------------------------------------------------------
+ */
+ if (H5Pclose(fcpl) < 0)
+ H5TOOLS_GOTO_ERROR((-1), "could not close fcpl");
+ if (H5Pclose(options->fout_fapl) < 0)
+ H5TOOLS_GOTO_ERROR((-1), "could not close fcpl");
+ options->fout_fapl = H5P_DEFAULT;
+ if (H5Pclose(gcpl_in) < 0)
+ H5TOOLS_GOTO_ERROR((-1), "could not close fcpl");
+ if (H5Gclose(grp_in) < 0)
+ H5TOOLS_GOTO_ERROR((-1), "could not close fcpl");
+ if (H5Fclose(fidout) < 0)
+ H5TOOLS_GOTO_ERROR((-1), "could not close fcpl");
+ if (H5Fclose(fidin) < 0)
+ H5TOOLS_GOTO_ERROR((-1), "could not close fcpl");
+
+ /*-------------------------------------------------------------------------
+ * NOTE: The userblock MUST be written out AFTER the file is closed or
+ * the file locking will cause failures on Windows, where file locks
+ * are mandatory, not advisory.
+ *-------------------------------------------------------------------------
+ */
+
+ /*-------------------------------------------------------------------------
+ * Write a new user block if requested, using the input file user block if
+ * there is no separate user block file input
*-------------------------------------------------------------------------
*/
- if (ub_size > 0 && options->ublock_size == 0)
+ if (options->ublock_size > 0) {
+ if (copy_user_block(options->ublock_filename, fnameout, options->ublock_size) < 0)
+ H5TOOLS_GOTO_ERROR((-1), "Could not copy user block. Exiting...");
+ }
+ else if (ub_size > 0 && options->ublock_size == 0) {
if (copy_user_block(fnamein, fnameout, ub_size) < 0)
H5TOOLS_GOTO_ERROR((-1), "Could not copy user block. Exiting...");
+ }
done:
- H5E_BEGIN_TRY
- {
- H5Pclose(fcpl);
- H5Pclose(options->fout_fapl);
- options->fout_fapl = H5P_DEFAULT;
- H5Pclose(gcpl_in);
- H5Gclose(grp_in);
- H5Pclose(fcpl_in);
- H5Fclose(fidout);
- H5Fclose(fidin);
+ if (-1 == ret_value) {
+ H5E_BEGIN_TRY
+ {
+ H5Pclose(fcpl);
+ H5Pclose(options->fout_fapl);
+ options->fout_fapl = H5P_DEFAULT;
+ H5Pclose(gcpl_in);
+ H5Gclose(grp_in);
+ H5Pclose(fcpl_in);
+ H5Fclose(fidout);
+ H5Fclose(fidin);
+ }
+ H5E_END_TRY;
}
- H5E_END_TRY;
if (travt)
trav_table_free(travt);