~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/cached_directory.cc

  • Committer: Padraig O'Sullivan
  • Date: 2009-09-13 01:03:01 UTC
  • mto: (1126.9.2 captain-20090915-01)
  • mto: This revision was merged to the branch mainline in revision 1133.
  • Revision ID: osullivan.padraig@gmail.com-20090913010301-tcvvezipx1124acy
Added calls to the dtrace delete begin/end probes.

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 <sys/types.h>
31
 
#include <sys/stat.h>
32
 
#include <unistd.h>
33
 
 
34
 
#include <strings.h>
35
 
#include <limits.h>
36
 
 
37
 
#include "drizzled/cached_directory.h"
 
28
#include "drizzled/global.h"
 
29
#include "cached_directory.h"
38
30
 
39
31
using namespace std;
40
32
 
41
 
namespace drizzled
42
 
{
43
 
 
44
 
CachedDirectory::CachedDirectory() : 
45
 
  error(0)
46
 
{
47
 
}
48
 
 
49
 
 
50
 
CachedDirectory::CachedDirectory(const string &in_path) :
51
 
  error(0)
52
 
{
53
 
  // TODO: Toss future exception
 
33
 
 
34
CachedDirectory::CachedDirectory(const string &in_path)
 
35
  : error(0)
 
36
{
54
37
  (void) open(in_path);
55
38
}
56
39
 
57
 
 
58
 
CachedDirectory::CachedDirectory(const string& in_path, set<string>& allowed_exts) :
59
 
  error(0)
60
 
{
61
 
  // TODO: Toss future exception
62
 
  (void) open(in_path, allowed_exts);
63
 
}
64
 
 
65
 
CachedDirectory::CachedDirectory(const string& in_path, enum CachedDirectory::FILTER filter) :
66
 
  error(0)
67
 
{
68
 
  set<string> empty;
69
 
  // TODO: Toss future exception
70
 
  (void) open(in_path, empty, filter);
71
 
}
72
 
 
73
 
 
74
40
CachedDirectory::~CachedDirectory()
75
41
{
76
 
  for (Entries::iterator p= entries.begin(); p != entries.end(); ++p)
 
42
  Entries::iterator p= entries.begin();
 
43
  while (p != entries.end())
77
44
  {
78
45
    if (*p)
79
46
      delete *p;
 
47
    ++p;
80
48
  }
81
 
  entries.clear();
82
49
}
83
50
 
84
51
bool CachedDirectory::open(const string &in_path)
85
52
{
86
 
  set<string> empty;
87
 
 
88
 
  return open(in_path, empty);
89
 
}
90
 
 
91
 
bool CachedDirectory::open(const string &in_path, set<string> &allowed_exts)
92
 
{
93
 
  return open(in_path, allowed_exts, CachedDirectory::NONE);
94
 
}
95
 
 
96
 
bool CachedDirectory::open(const string &in_path, set<string> &allowed_exts, enum CachedDirectory::FILTER filter)
97
 
{
98
53
  DIR *dirp= opendir(in_path.c_str());
99
54
 
100
55
  if (dirp == NULL)
103
58
    return false;
104
59
  }
105
60
 
106
 
  path= in_path;
107
 
 
108
61
  union {
109
62
    dirent entry;
110
63
#ifdef __sun
124
77
 
125
78
  while ((retcode= readdir_r(dirp, &buffer.entry, &result)) == 0 &&
126
79
         result != NULL)
127
 
  {
128
 
    if (! allowed_exts.empty())
129
 
    {
130
 
      char *ptr= rindex(result->d_name, '.');
131
 
 
132
 
      if (ptr)
133
 
      {
134
 
        set<string>::iterator it;
135
 
        it= allowed_exts.find(ptr);
136
 
 
137
 
        if (it != allowed_exts.end())
138
 
        {
139
 
          entries.push_back(new Entry(result->d_name));
140
 
        }
141
 
      }
142
 
    }
143
 
    else
144
 
    {
145
 
      switch (filter)
146
 
      {
147
 
      case DIRECTORY:
148
 
        {
149
 
          struct stat entrystat;
150
 
 
151
 
          if (result->d_name[0] == '.')
152
 
            continue;
153
 
 
154
 
          stat(result->d_name, &entrystat);
155
 
 
156
 
          if (S_ISDIR(entrystat.st_mode))
157
 
          {
158
 
            entries.push_back(new Entry(result->d_name));
159
 
          }
160
 
        }
161
 
        break;
162
 
      case FILE:
163
 
        {
164
 
          struct stat entrystat;
165
 
 
166
 
          stat(result->d_name, &entrystat);
167
 
 
168
 
          if (S_ISREG(entrystat.st_mode))
169
 
          {
170
 
            entries.push_back(new Entry(result->d_name));
171
 
          }
172
 
        }
173
 
        break;
174
 
      case NONE:
175
 
      case MAX:
176
 
        entries.push_back(new Entry(result->d_name));
177
 
        break;
178
 
      }
179
 
    }
180
 
  }
 
80
    entries.push_back(new Entry(result->d_name));
181
81
    
182
82
  closedir(dirp);
183
83
  error= retcode;
184
84
 
185
85
  return error == 0;
186
86
}
187
 
 
188
 
} /* namespace drizzled */