summaryrefslogtreecommitdiff
path: root/src/os_posix/os_remove.c
blob: f802a62f32f0eb03ed091bda9b3e33a233ba9316 (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
/*-
 * See the file LICENSE for redistribution information.
 *
 * Copyright (c) 2008-2011 WiredTiger, Inc.
 *	All rights reserved.
 */

#include "wt_internal.h"

/*
 * __wt_remove --
 *	Remove a file.
 */
int
__wt_remove(WT_SESSION_IMPL *session, const char *name)
{
	WT_CONNECTION_IMPL *conn;
	WT_FH *fh;
	int ret;

	conn = S2C(session);
	fh = NULL;

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

	/* If the file is open, close/free it. */
	__wt_lock(session, conn->mtx);
	TAILQ_FOREACH(fh, &conn->fhqh, q) {
		if (strcmp(name, fh->name) == 0)
			break;
	}
	__wt_unlock(session, conn->mtx);

	/* This should be caught at a higher level. */
	WT_ASSERT(session, fh == NULL);

	SYSCALL_RETRY(remove(name), ret);
	if (ret == 0)
		return (0);
	__wt_err(session, errno, "%s", name);
	return (WT_ERROR);
}