Skip to content

Commit

Permalink
[1.10 Merge] Avoid suppressing error output for non-tentative file op…
Browse files Browse the repository at this point in the history
…ens (#2632) (#2668)
  • Loading branch information
jhendersonHDF authored Apr 8, 2023
1 parent de9fab1 commit 3e689af
Showing 1 changed file with 48 additions and 20 deletions.
68 changes: 48 additions & 20 deletions src/H5Fint.c
Original file line number Diff line number Diff line change
Expand Up @@ -1647,34 +1647,62 @@ H5F_open(const char *name, unsigned flags, hid_t fcpl_id, hid_t fapl_id)
else
tent_flags = flags;

if (NULL == (lf = H5FD_open(name, tent_flags, fapl_id, HADDR_UNDEF))) {
if (tent_flags == flags) {
#ifndef H5_USING_MEMCHECKER
time_t mytime = HDtime(NULL);
/*
* When performing a tentative open of a file where we have stripped away
* flags such as H5F_ACC_CREAT from the specified file access flags, the
* H5E_BEGIN/END_TRY macros are used to suppress error output since there
* is an expectation that the tentative open might fail. Even though we
* explicitly clear the error stack after such a failure, the underlying
* file driver might maintain its own error stack and choose whether to
* display errors based on whether the library has disabled error reporting.
* Since we wish to suppress that error output as well for the case of
* tentative file opens, surrounding the file open call with the
* H5E_BEGIN/END_TRY macros is an explicit instruction to the file driver
* not to display errors. If the tentative file open call fails, another
* attempt at opening the file will be made without error output being
* suppressed.
*
* However, if stripping away the H5F_ACC_CREAT flag and others left us
* with the same file access flags as before, then we will skip this
* tentative file open and only make a single attempt at opening the file.
* In this case, we don't want to suppress error output since the underlying
* file driver might provide more details on why the file open failed.
*/
if (tent_flags != flags) {
/* Make tentative attempt to open file */
H5E_BEGIN_TRY
{
lf = H5FD_open(name, tent_flags, fapl_id, HADDR_UNDEF);
}
H5E_END_TRY;
}

HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL,
"unable to open file: time = %s, name = '%s', tent_flags = %x", HDctime(&mytime),
name, tent_flags)
#else /* H5_USING_MEMCHECKER */
HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL, "unable to open file: name = '%s', tent_flags = %x",
name, tent_flags)
#endif /* H5_USING_MEMCHECKER */
} /* end if */
H5E_clear_stack(NULL);
tent_flags = flags;
if (NULL == (lf = H5FD_open(name, tent_flags, fapl_id, HADDR_UNDEF))) {
/*
* If a tentative attempt to open the file wasn't necessary, attempt
* to open the file now. Otherwise, if the tentative open failed, clear
* the error stack and reset the file access flags, then make another
* attempt at opening the file.
*/
if ((tent_flags == flags) || (lf == NULL)) {
#ifndef H5_USING_MEMCHECKER
time_t mytime = HDtime(NULL);
time_t mytime = HDtime(NULL);
#endif

if (tent_flags != flags) {
H5E_clear_stack(NULL);
tent_flags = flags;
}

if (NULL == (lf = H5FD_open(name, tent_flags, fapl_id, HADDR_UNDEF)))
#ifndef H5_USING_MEMCHECKER
HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL,
"unable to open file: time = %s, name = '%s', tent_flags = %x", HDctime(&mytime),
name, tent_flags)
#else /* H5_USING_MEMCHECKER */
#else
HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL, "unable to open file: name = '%s', tent_flags = %x",
name, tent_flags)
#endif /* H5_USING_MEMCHECKER */
} /* end if */
} /* end if */
#endif
}

/* Is the file already open? */
if ((shared = H5F__sfile_search(lf)) != NULL) {
Expand Down

0 comments on commit 3e689af

Please sign in to comment.