~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/pbms/src/cslib/CSDirectory.cc

  • Committer: Mark Atwood
  • Date: 2011-12-20 02:32:53 UTC
  • mfrom: (2469.1.1 drizzle-build)
  • Revision ID: me@mark.atwood.name-20111220023253-bvu0kr14kwsdvz7g
mergeĀ lp:~brianaker/drizzle/deprecate-pbms

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2008 PrimeBase Technologies GmbH, Germany
2
 
 *
3
 
 * PrimeBase Media Stream for MySQL
4
 
 *
5
 
 * This program is free software; you can redistribute it and/or modify
6
 
 * it under the terms of the GNU General Public License as published by
7
 
 * the Free Software Foundation; either version 2 of the License, or
8
 
 * (at your option) any later version.
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
 
 * Original author: Paul McCullagh (H&G2JCtL)
20
 
 * Continued development: Barry Leslie
21
 
 *
22
 
 * 2007-06-07
23
 
 *
24
 
 * CORE SYSTEM:
25
 
 * A basic directory.
26
 
 *
27
 
 */
28
 
 
29
 
#include "CSConfig.h"
30
 
 
31
 
#include <string.h>
32
 
 
33
 
#include "CSStrUtil.h"
34
 
#include "CSPath.h"
35
 
#include "CSDirectory.h"
36
 
#include "CSGlobal.h"
37
 
 
38
 
/*
39
 
 * ---------------------------------------------------------------
40
 
 * CORE SYSTEM DIRECTORY
41
 
 */
42
 
 
43
 
void CSDirectory::print(CSOutputStream *out)
44
 
{
45
 
        char    buffer[500];
46
 
        char    number[50];
47
 
        bool    is_dir;
48
 
        off64_t size;
49
 
        CSTime  mod_time;
50
 
        char    *str_time;
51
 
 
52
 
        while (next()) {
53
 
                info(&is_dir, &size, &mod_time); 
54
 
                if (is_dir)
55
 
                        cs_strcpy(500, buffer, "D");
56
 
                else
57
 
                        cs_strcpy(500, buffer, "f");
58
 
                snprintf(number, 50, "%8llu ", (unsigned long long) size);
59
 
                cs_strcat(500, buffer, number);
60
 
                str_time = mod_time.getCString();
61
 
                cs_strcat(500, buffer, str_time);
62
 
                cs_strcat(500, buffer, " ");
63
 
                cs_strcat(500, buffer, name());
64
 
                out->printLine(buffer);
65
 
        }
66
 
}
67
 
 
68
 
void CSDirectory::deleteEntry()
69
 
{
70
 
        char path[PATH_MAX];
71
 
 
72
 
        enter_();
73
 
        
74
 
        getEntryPath(path, PATH_MAX);
75
 
        
76
 
        CSPath *cs_path = CSPath::newPath(path);
77
 
        push_(cs_path);
78
 
        cs_path->removeFile();
79
 
        release_(cs_path);
80
 
 
81
 
        exit_();
82
 
}
83
 
 
84
 
const char *CSDirectory::name()
85
 
{
86
 
        return entryName();
87
 
}
88
 
 
89
 
bool CSDirectory::isFile()
90
 
{
91
 
        return entryIsFile();
92
 
}
93
 
 
94
 
off64_t CSDirectory::getSize()
95
 
{
96
 
        char path[PATH_MAX];
97
 
 
98
 
        getEntryPath(path, PATH_MAX);
99
 
        
100
 
        return CSPath::getSize(path);
101
 
}
102
 
 
103
 
void CSDirectory::info(bool *is_dir, off64_t *size, CSTime *mod_time)
104
 
{
105
 
        char path[PATH_MAX];
106
 
 
107
 
        getEntryPath(path, PATH_MAX);
108
 
        
109
 
        CSPath::info(path, is_dir, size, mod_time);
110
 
}
111
 
 
112
 
bool CSDirectory::exists()
113
 
{
114
 
        CSPath *path;
115
 
        bool yup;
116
 
 
117
 
        enter_();
118
 
        path = CSPath::newPath(RETAIN(sd_path));
119
 
        push_(path);
120
 
        yup = path->exists();
121
 
        release_(path);
122
 
        return_(yup);
123
 
}
124
 
 
125
 
CSDirectory *CSDirectory::newDirectory(CSString *path)
126
 
{
127
 
        CSDirectory *dir;
128
 
 
129
 
        if (!(dir = new CSDirectory())) {
130
 
                path->release();
131
 
                CSException::throwOSError(CS_CONTEXT, ENOMEM);
132
 
        }
133
 
        dir->sd_path = path;
134
 
        return dir;
135
 
}
136
 
 
137
 
CSDirectory *CSDirectory::newDirectory(CSPath *path)
138
 
{
139
 
        CSDirectory *dir;
140
 
        enter_();
141
 
        
142
 
        push_(path);
143
 
        dir = newDirectory(RETAIN(path->getString()));
144
 
        release_(path);
145
 
        return_(dir);
146
 
}
147
 
 
148
 
CSDirectory *CSDirectory::newDirectory(const char *path)
149
 
{
150
 
        return newDirectory(CSString::newString(path));
151
 
}
152
 
 
153