1 /* Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
2 
3    This program is free software; you can redistribute it and/or modify
4    it under the terms of the GNU General Public License, version 2.0,
5    as published by the Free Software Foundation.
6 
7    This program is also distributed with certain software (including
8    but not limited to OpenSSL) that is licensed under separate terms,
9    as designated in a particular file or component or in included license
10    documentation.  The authors of MySQL hereby grant you an additional
11    permission to link the program and your derivative works with the
12    separately licensed software that they have included with MySQL.
13 
14    This program 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, version 2.0, for more details.
18 
19    You should have received a copy of the GNU General Public License
20    along with this program; if not, write to the Free Software
21    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA */
22 
23 #ifndef NdbDir_HPP
24 #define NdbDir_HPP
25 
26 #ifdef _WIN32
27 #ifndef mode_t /* MySQL 5.5+ defines mode_t */
28 typedef int mode_t;
29 #endif
30 #endif
31 
32 class NdbDir {
33 public:
34   class Iterator {
35     class DirIteratorImpl& m_impl;
36     Iterator(const Iterator&);  // not impl
37     Iterator& operator=(const Iterator&); // not impl
38   public:
39     Iterator();
40     ~Iterator();
41 
42     int open(const char* path);
43     void close(void);
44 
45     /*
46       Return the next regular file or NULL if no more file found
47     */
48     const char* next_file(void);
49 
50     /*
51       Return the next entry(file, dir, symlink etc.) or NULL if no
52       more entries found
53     */
54     const char* next_entry(void);
55   };
56 
57   class Temp {
58     const char* m_path;
59     Temp(const Temp&);  // not impl
60     Temp& operator=(const Temp&); // not impl
61   public:
62     Temp();
63     ~Temp();
64     const char* path(void) const;
65   };
66 
67   static mode_t u_r(void);
68   static mode_t u_w(void);
69   static mode_t u_x(void);
u_rwx(void)70   static mode_t u_rwx(void) { return (u_r() | u_w() | u_x()); }
71 
72   static mode_t g_r(void);
73   static mode_t g_w(void);
74   static mode_t g_x(void);
g_rwx(void)75   static mode_t g_rwx(void) { return (g_r() | g_w() | g_x()); }
76 
77   static mode_t o_r(void);
78   static mode_t o_w(void);
79   static mode_t o_x(void);
o_rwx(void)80   static mode_t o_rwx(void) { return (o_r() | o_w() | o_x()); }
81 
82   /*
83     Create directory
84      path - path to directory to create
85      mode - mode for the directory to create
86      ignore_existing - don't print or return error if directory
87                        already exist
88   */
89   static bool create(const char *path,
90                      mode_t mode = u_rwx(),
91                      bool ignore_existing = false);
92 
93   /*
94     Remove directory recursively
95       path - path to directory that should be removed
96       only_contents - only remove the contents of the directory
97 
98   */
99   static bool remove_recursive(const char* path, bool only_contents = false);
100 
101   /*
102     Remove empty directory
103   */
104   static bool remove(const char* path);
105 
106   /*
107     Change working directory
108   */
109   static int chdir(const char* path);
110 
111 };
112 
113 #endif
114