summaryrefslogtreecommitdiff
path: root/src/third_party/wiredtiger/src/support/filename.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/third_party/wiredtiger/src/support/filename.c')
-rw-r--r--src/third_party/wiredtiger/src/support/filename.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/src/third_party/wiredtiger/src/support/filename.c b/src/third_party/wiredtiger/src/support/filename.c
index 6d65cdf9ada..db466ed3bd4 100644
--- a/src/third_party/wiredtiger/src/support/filename.c
+++ b/src/third_party/wiredtiger/src/support/filename.c
@@ -48,3 +48,67 @@ __wt_nfilename(
return (0);
}
+
+/*
+ * __wt_remove_if_exists --
+ * Remove a file if it exists.
+ */
+int
+__wt_remove_if_exists(WT_SESSION_IMPL *session, const char *name)
+{
+ int exist;
+
+ WT_RET(__wt_exist(session, name, &exist));
+ if (exist)
+ WT_RET(__wt_remove(session, name));
+ return (0);
+}
+
+/*
+ * __wt_sync_and_rename_fh --
+ * Sync and close a file, and swap it into place.
+ */
+int
+__wt_sync_and_rename_fh(
+ WT_SESSION_IMPL *session, WT_FH **fhp, const char *from, const char *to)
+{
+ WT_DECL_RET;
+ WT_FH *fh;
+
+ fh = *fhp;
+ *fhp = NULL;
+
+ /* Flush to disk and close the handle. */
+ ret = __wt_fsync(session, fh);
+ WT_TRET(__wt_close(session, &fh));
+ WT_RET(ret);
+
+ /* Rename the source file to the target. */
+ WT_RET(__wt_rename(session, from, to));
+
+ /* Flush the backing directory to guarantee the rename. */
+ return (__wt_directory_sync(session, NULL));
+}
+
+/*
+ * __wt_sync_and_rename_fp --
+ * Sync and close a file, and swap it into place.
+ */
+int
+__wt_sync_and_rename_fp(
+ WT_SESSION_IMPL *session, FILE **fpp, const char *from, const char *to)
+{
+ FILE *fp;
+
+ fp = *fpp;
+ *fpp = NULL;
+
+ /* Flush to disk and close the handle. */
+ WT_RET(__wt_fclose(session, &fp, WT_FHANDLE_WRITE));
+
+ /* Rename the source file to the target. */
+ WT_RET(__wt_rename(session, from, to));
+
+ /* Flush the backing directory to guarantee the rename. */
+ return (__wt_directory_sync(session, NULL));
+}