/* Rename the checkpoint file from the temporary to the final name */
mpiBarrierBeforeRename(applyMpiBarrierBeforeRename, mpiBarrierCommunicator);
- if (gmx_file_rename(fntemp, fn) != 0)
+ try
{
- gmx_file("Cannot rename checkpoint file; maybe you are out of disk space?");
+ gmx_file_rename(fntemp, fn);
+ }
+ catch (gmx::FileIOError const&)
+ {
+ // In this case we can be more helpful than the generic message from gmx_file_rename
+ GMX_THROW(gmx::FileIOError(
+ "Cannot rename checkpoint file; maybe you are out of disk space?"));
}
}
#endif /* GMX_NO_RENAME */
return fpout;
}
-int gmx_file_rename(const char* oldname, const char* newname)
+void gmx_file_rename(const char* oldname, const char* newname)
{
+ int code;
#if !GMX_NATIVE_WINDOWS
/* under unix, rename() is atomic (at least, it should be). */
- return rename(oldname, newname);
+ code = rename(oldname, newname);
#else
if (MoveFileEx(oldname, newname, MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH))
{
/* This just lets the F@H checksumming system know about the rename */
fcRename(oldname, newname);
# endif
- return 0;
+ code = 0;
}
else
{
- return 1;
+ code = 1;
}
#endif
+ if (code != 0)
+ {
+ auto errorMsg = gmx::formatString("Failed to rename %s to %s.", oldname, newname);
+ GMX_THROW(gmx::FileIOError(errorMsg));
+ }
}
int gmx_file_copy(const char* oldname, const char* newname, gmx_bool copy_if_empty)
*
* Copyright (c) 1991-2000, University of Groningen, The Netherlands.
* Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014,2015,2018,2019, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015,2018,2019,2021, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
*
* Renames/moves a file atomically, if the OS makes that available.
*/
-int gmx_file_rename(const char* oldname, const char* newname);
+void gmx_file_rename(const char* oldname, const char* newname);
/*! \brief
* Copies a file (data only) oldname to newname.