summaryrefslogtreecommitdiff
path: root/src/os_posix/os_remove.c
blob: a7e511b48d77ee424f0538a68bd1319f3a0c6d25 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*-
 * Copyright (c) 2008-2014 WiredTiger, Inc.
 *	All rights reserved.
 *
 * See the file LICENSE for redistribution information.
 */

#include "wt_internal.h"

/*
 * __remove_file_check --
 *	Check if the file is currently open before removing it.
 */
static inline void
__remove_file_check(WT_SESSION_IMPL *session, const char *name)
{
#ifdef HAVE_DIAGNOSTIC
	WT_CONNECTION_IMPL *conn;
	WT_FH *fh;

	conn = S2C(session);
	fh = NULL;

	/*
	 * Check if the file is open: it's an error if it is, since a higher
	 * level should have closed it before removing.
	 */
	__wt_spin_lock(session, &conn->fh_lock);
	TAILQ_FOREACH(fh, &conn->fhqh, q) {
		if (strcmp(name, fh->name) == 0)
			break;
	}
	__wt_spin_unlock(session, &conn->fh_lock);

	WT_ASSERT(session, fh == NULL);
#else
	WT_UNUSED(session);
	WT_UNUSED(name);
#endif
}

/*
 * __wt_remove --
 *	Remove a file.
 */
int
__wt_remove(WT_SESSION_IMPL *session, const char *name)
{
	WT_DECL_RET;
	char *path;

	WT_VERBOSE_RET(session, fileops, "%s: remove", name);

	__remove_file_check(session, name);

	WT_RET(__wt_filename(session, name, &path));

	WT_SYSCALL_RETRY(remove(path), ret);

	__wt_free(session, path);

	if (ret == 0 || ret == ENOENT)
		return (0);

	WT_RET_MSG(session, ret, "%s: remove", name);
}