MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NDBT_Workingdir.hpp
1 /*
2  Copyright 2009 Sun Microsystems, Inc.
3 
4  All rights reserved. Use is subject to license terms.
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; version 2 of the License.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
20 #ifndef NDBT_WORKINGDIR_HPP
21 #define NDBT_WORKINGDIR_HPP
22 
23 #include <NdbDir.hpp>
24 #include <BaseString.hpp>
25 #include <NdbProcess.hpp>
26 
28 {
29  NdbDir::Temp m_temp;
30  BaseString m_wd;
31 public:
32 
33  NDBT_Workingdir(const char* dirname)
34  {
35  const char* tmp_path = m_temp.path();
36  char* ndbt_tmp = getenv("NDBT_TMP_DIR");
37  if (ndbt_tmp)
38  tmp_path = ndbt_tmp;
39  assert(tmp_path);
40 
41  m_wd.assfmt("%s%s%s%d", tmp_path, DIR_SEPARATOR, dirname,
42  (int)NdbProcess::getpid());
43  if (access(m_wd.c_str(), F_OK) == 0)
44  NdbDir::remove_recursive(m_wd.c_str());
45  if (!NdbDir::create(m_wd.c_str()))
46  abort();
47  }
48 
50  {
51  if (access(m_wd.c_str(), F_OK) == 0)
52  NdbDir::remove_recursive(m_wd.c_str());
53  }
54 
55  const char* path(void) const
56  {
57  return m_wd.c_str();
58  }
59 
60 };
61 
62 #endif