~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/cached_directory.cc

  • Committer: Eric Day
  • Date: 2009-11-10 21:50:22 UTC
  • mto: This revision was merged to the branch mainline in revision 1218.
  • Revision ID: eday@oddments.org-20091110215022-0b2nqmurv7b2l6wo
Duplicated oldlibdrizzle module, one for Drizzle protocol and one for MySQL, per Brian's request from merge proposal. Port options are now --drizzle-protocol-port and --mysql-protocol-port.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
 *   Implementation of CachedDirectory class.
26
26
 */
27
27
 
28
 
#include "config.h"
29
 
 
30
 
#include "drizzled/definitions.h"
31
 
 
32
 
#include <sys/types.h>
33
 
#include <sys/stat.h>
34
 
#include <unistd.h>
35
 
 
36
28
#include <strings.h>
37
 
#include <limits.h>
38
 
 
39
 
#include "drizzled/cached_directory.h"
 
29
#include "drizzled/global.h"
 
30
#include "cached_directory.h"
40
31
 
41
32
using namespace std;
42
33
 
43
 
namespace drizzled
44
 
{
45
34
 
46
35
CachedDirectory::CachedDirectory() : 
47
36
  error(0)
57
46
}
58
47
 
59
48
 
60
 
CachedDirectory::CachedDirectory(const string& in_path, set<string>& allowed_exts) :
61
 
  error(0)
62
 
{
63
 
  // TODO: Toss future exception
64
 
  (void) open(in_path, allowed_exts);
65
 
}
66
 
 
67
 
CachedDirectory::CachedDirectory(const string& in_path, enum CachedDirectory::FILTER filter) :
68
 
  error(0)
69
 
{
70
 
  set<string> empty;
71
 
  // TODO: Toss future exception
72
 
  (void) open(in_path, empty, filter);
 
49
CachedDirectory::CachedDirectory(const string& in_path, set<string>& exts) :
 
50
  error(0)
 
51
{
 
52
  // TODO: Toss future exception
 
53
  (void) open(in_path, exts, true);
73
54
}
74
55
 
75
56
 
83
64
  entries.clear();
84
65
}
85
66
 
 
67
 
86
68
bool CachedDirectory::open(const string &in_path)
87
69
{
88
70
  set<string> empty;
89
71
 
90
 
  return open(in_path, empty);
91
 
}
92
 
 
93
 
bool CachedDirectory::open(const string &in_path, set<string> &allowed_exts)
94
 
{
95
 
  return open(in_path, allowed_exts, CachedDirectory::NONE);
96
 
}
97
 
 
98
 
bool CachedDirectory::open(const string &in_path, set<string> &allowed_exts, enum CachedDirectory::FILTER filter)
 
72
  return open(in_path, empty, false);
 
73
}
 
74
 
 
75
bool CachedDirectory::open(const string &in_path, set<string> exts, bool honor_exts)
99
76
{
100
77
  DIR *dirp= opendir(in_path.c_str());
101
78
 
107
84
 
108
85
  path= in_path;
109
86
 
 
87
  if (exts.size() == 0 && honor_exts)
 
88
    return true;
 
89
 
110
90
  union {
111
91
    dirent entry;
112
92
#ifdef __sun
127
107
  while ((retcode= readdir_r(dirp, &buffer.entry, &result)) == 0 &&
128
108
         result != NULL)
129
109
  {
130
 
    std::string buffered_fullpath;
131
 
    if (! allowed_exts.empty())
 
110
    if (exts.size())
132
111
    {
133
112
      char *ptr= rindex(result->d_name, '.');
134
113
 
135
114
      if (ptr)
136
115
      {
137
116
        set<string>::iterator it;
138
 
        it= allowed_exts.find(ptr);
 
117
        it= exts.find(ptr);
139
118
 
140
 
        if (it != allowed_exts.end())
 
119
        if (it != exts.end())
141
120
        {
142
121
          entries.push_back(new Entry(result->d_name));
143
122
        }
145
124
    }
146
125
    else
147
126
    {
148
 
      switch (filter)
149
 
      {
150
 
      case DIRECTORY:
151
 
        {
152
 
          struct stat entrystat;
153
 
 
154
 
          if (result->d_name[0] == '.') // We don't pass back anything hidden at the moment.
155
 
            continue;
156
 
 
157
 
          buffered_fullpath.append(in_path);
158
 
          if (buffered_fullpath[buffered_fullpath.length()] != '/')
159
 
            buffered_fullpath.append(1, FN_LIBCHAR);
160
 
 
161
 
          buffered_fullpath.assign(result->d_name);
162
 
 
163
 
          stat(buffered_fullpath.c_str(), &entrystat);
164
 
 
165
 
          if (S_ISDIR(entrystat.st_mode))
166
 
          {
167
 
            entries.push_back(new Entry(result->d_name));
168
 
          }
169
 
        }
170
 
        break;
171
 
      case FILE:
172
 
        {
173
 
          struct stat entrystat;
174
 
 
175
 
          buffered_fullpath.append(in_path);
176
 
          if (buffered_fullpath[buffered_fullpath.length()] != '/')
177
 
            buffered_fullpath.append(1, FN_LIBCHAR);
178
 
 
179
 
          buffered_fullpath.assign(result->d_name);
180
 
 
181
 
          stat(buffered_fullpath.c_str(), &entrystat);
182
 
 
183
 
          if (S_ISREG(entrystat.st_mode))
184
 
          {
185
 
            entries.push_back(new Entry(result->d_name));
186
 
          }
187
 
        }
188
 
        break;
189
 
      case NONE:
190
 
      case MAX:
191
 
        entries.push_back(new Entry(result->d_name));
192
 
        break;
193
 
      }
 
127
      entries.push_back(new Entry(result->d_name));
194
128
    }
195
129
  }
196
130
    
199
133
 
200
134
  return error == 0;
201
135
}
202
 
 
203
 
} /* namespace drizzled */