1 /* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 // vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4:
3 #ident "$Id$"
4 /*======
5 This file is part of PerconaFT.
6
7
8 Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved.
9
10 PerconaFT is free software: you can redistribute it and/or modify
11 it under the terms of the GNU General Public License, version 2,
12 as published by the Free Software Foundation.
13
14 PerconaFT is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with PerconaFT. If not, see <http://www.gnu.org/licenses/>.
21
22 ----------------------------------------
23
24 PerconaFT is free software: you can redistribute it and/or modify
25 it under the terms of the GNU Affero General Public License, version 3,
26 as published by the Free Software Foundation.
27
28 PerconaFT is distributed in the hope that it will be useful,
29 but WITHOUT ANY WARRANTY; without even the implied warranty of
30 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 GNU Affero General Public License for more details.
32
33 You should have received a copy of the GNU Affero General Public License
34 along with PerconaFT. If not, see <http://www.gnu.org/licenses/>.
35 ======= */
36
37 #ident "Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved."
38
39 #include "test.h"
40
41
42 // Try to open an environment where the directory does not exist
43 // Try when the dir exists but is not an initialized env
44 // Try when the dir exists and we do DB_CREATE: it should work.
45 // And after that the open should work without a DB_CREATE
46 // However, in BDB, after doing an DB_ENV->open and then a close, no state has changed
47 // One must actually create a DB I think...
48
49
50 #include <db.h>
51 #include <errno.h>
52 #include <stdio.h>
53 #include <stdlib.h>
54 #include <sys/stat.h>
55 #include <sys/types.h>
56
57 #include <unistd.h>
58
59 // TOKU_TEST_FILENAME is defined in the Makefile
60
61 int
test_main(int argc,char * const argv[])62 test_main(int argc, char *const argv[]) {
63 parse_args(argc, argv);
64 DB_ENV *dbenv;
65 int r;
66 int do_private;
67
68 for (do_private=0; do_private<2; do_private++) {
69 if (do_private==0) continue; // See #208.
70 int private_flags = do_private ? (DB_CREATE|DB_PRIVATE) : 0;
71
72 toku_os_recursive_delete(TOKU_TEST_FILENAME);
73 r = db_env_create(&dbenv, 0);
74 CKERR(r);
75 r = dbenv->open(dbenv, TOKU_TEST_FILENAME, private_flags|DB_INIT_MPOOL, 0);
76 assert(r==ENOENT);
77 dbenv->close(dbenv,0); // free memory
78
79 toku_os_recursive_delete(TOKU_TEST_FILENAME);
80 toku_os_mkdir(TOKU_TEST_FILENAME, S_IRWXU+S_IRWXG+S_IRWXO);
81 r = db_env_create(&dbenv, 0);
82 CKERR(r);
83 r = dbenv->open(dbenv, TOKU_TEST_FILENAME, private_flags|DB_INIT_MPOOL, 0);
84 // PerconaFT has no trouble opening an environment if the directory exists.
85 CKERR(r);
86 assert(r==0);
87 dbenv->close(dbenv,0); // free memory
88 }
89
90 return 0;
91 }
92
93