16
16
17
17
using namespace fs ;
18
18
19
- FileImplPtr VFSImpl::open (const char * path , const char * mode)
19
+ FileImplPtr VFSImpl::open (const char * fpath , const char * mode)
20
20
{
21
21
if (!_mountpoint) {
22
22
log_e (" File system is not mounted" );
23
23
return FileImplPtr ();
24
24
}
25
25
26
- if (!path || path [0 ] != ' /' ) {
27
- log_e (" %s does not start with /" , path );
26
+ if (!fpath || fpath [0 ] != ' /' ) {
27
+ log_e (" %s does not start with /" , fpath );
28
28
return FileImplPtr ();
29
29
}
30
30
31
- char * temp = (char *)malloc (strlen (path )+strlen (_mountpoint)+2 );
31
+ char * temp = (char *)malloc (strlen (fpath )+strlen (_mountpoint)+2 );
32
32
if (!temp) {
33
33
log_e (" malloc failed" );
34
34
return FileImplPtr ();
35
35
}
36
36
37
- sprintf (temp," %s%s" , _mountpoint, path );
37
+ sprintf (temp," %s%s" , _mountpoint, fpath );
38
38
39
39
struct stat st;
40
40
// file lound
41
41
if (!stat (temp, &st)) {
42
42
free (temp);
43
43
if (S_ISREG (st.st_mode ) || S_ISDIR (st.st_mode )) {
44
- return std::make_shared<VFSFileImpl>(this , path , mode);
44
+ return std::make_shared<VFSFileImpl>(this , fpath , mode);
45
45
}
46
- log_e (" %s has wrong mode 0x%08X" , path , st.st_mode );
46
+ log_e (" %s has wrong mode 0x%08X" , fpath , st.st_mode );
47
47
return FileImplPtr ();
48
48
}
49
49
50
50
// file not found but mode permits creation
51
51
if (mode && mode[0 ] != ' r' ) {
52
52
free (temp);
53
- return std::make_shared<VFSFileImpl>(this , path , mode);
53
+ return std::make_shared<VFSFileImpl>(this , fpath , mode);
54
54
}
55
55
56
56
// try to open this as directory (might be mount point)
57
57
DIR * d = opendir (temp);
58
58
if (d) {
59
59
closedir (d);
60
60
free (temp);
61
- return std::make_shared<VFSFileImpl>(this , path , mode);
61
+ return std::make_shared<VFSFileImpl>(this , fpath , mode);
62
62
}
63
63
64
64
log_e (" %s does not exist" , temp);
65
65
free (temp);
66
66
return FileImplPtr ();
67
67
}
68
68
69
- bool VFSImpl::exists (const char * path )
69
+ bool VFSImpl::exists (const char * fpath )
70
70
{
71
71
if (!_mountpoint) {
72
72
log_e (" File system is not mounted" );
73
73
return false ;
74
74
}
75
75
76
- VFSFileImpl f (this , path , " r" );
76
+ VFSFileImpl f (this , fpath , " r" );
77
77
if (f) {
78
78
f.close ();
79
79
return true ;
@@ -115,69 +115,69 @@ bool VFSImpl::rename(const char* pathFrom, const char* pathTo)
115
115
return rc == 0 ;
116
116
}
117
117
118
- bool VFSImpl::remove (const char * path )
118
+ bool VFSImpl::remove (const char * fpath )
119
119
{
120
120
if (!_mountpoint) {
121
121
log_e (" File system is not mounted" );
122
122
return false ;
123
123
}
124
124
125
- if (!path || path [0 ] != ' /' ) {
125
+ if (!fpath || fpath [0 ] != ' /' ) {
126
126
log_e (" bad arguments" );
127
127
return false ;
128
128
}
129
129
130
- VFSFileImpl f (this , path , " r" );
130
+ VFSFileImpl f (this , fpath , " r" );
131
131
if (!f || f.isDirectory ()) {
132
132
if (f) {
133
133
f.close ();
134
134
}
135
- log_e (" %s does not exists or is directory" , path );
135
+ log_e (" %s does not exists or is directory" , fpath );
136
136
return false ;
137
137
}
138
138
f.close ();
139
139
140
- char * temp = (char *)malloc (strlen (path )+strlen (_mountpoint)+1 );
140
+ char * temp = (char *)malloc (strlen (fpath )+strlen (_mountpoint)+1 );
141
141
if (!temp) {
142
142
log_e (" malloc failed" );
143
143
return false ;
144
144
}
145
- sprintf (temp," %s%s" , _mountpoint, path );
145
+ sprintf (temp," %s%s" , _mountpoint, fpath );
146
146
auto rc = unlink (temp);
147
147
free (temp);
148
148
return rc == 0 ;
149
149
}
150
150
151
- bool VFSImpl::mkdir (const char *path )
151
+ bool VFSImpl::mkdir (const char *fpath )
152
152
{
153
153
if (!_mountpoint) {
154
154
log_e (" File system is not mounted" );
155
155
return false ;
156
156
}
157
157
158
- VFSFileImpl f (this , path , " r" );
158
+ VFSFileImpl f (this , fpath , " r" );
159
159
if (f && f.isDirectory ()) {
160
160
f.close ();
161
- // log_w("%s already exists", path );
161
+ // log_w("%s already exists", fpath );
162
162
return true ;
163
163
} else if (f) {
164
164
f.close ();
165
- log_e (" %s is a file" , path );
165
+ log_e (" %s is a file" , fpath );
166
166
return false ;
167
167
}
168
168
169
- char * temp = (char *)malloc (strlen (path )+strlen (_mountpoint)+1 );
169
+ char * temp = (char *)malloc (strlen (fpath )+strlen (_mountpoint)+1 );
170
170
if (!temp) {
171
171
log_e (" malloc failed" );
172
172
return false ;
173
173
}
174
- sprintf (temp," %s%s" , _mountpoint, path );
174
+ sprintf (temp," %s%s" , _mountpoint, fpath );
175
175
auto rc = ::mkdir (temp, ACCESSPERMS);
176
176
free (temp);
177
177
return rc == 0 ;
178
178
}
179
179
180
- bool VFSImpl::rmdir (const char *path )
180
+ bool VFSImpl::rmdir (const char *fpath )
181
181
{
182
182
if (!_mountpoint) {
183
183
log_e (" File system is not mounted" );
@@ -189,22 +189,22 @@ bool VFSImpl::rmdir(const char *path)
189
189
return false ;
190
190
}
191
191
192
- VFSFileImpl f (this , path , " r" );
192
+ VFSFileImpl f (this , fpath , " r" );
193
193
if (!f || !f.isDirectory ()) {
194
194
if (f) {
195
195
f.close ();
196
196
}
197
- log_e (" %s does not exists or is a file" , path );
197
+ log_e (" %s does not exists or is a file" , fpath );
198
198
return false ;
199
199
}
200
200
f.close ();
201
201
202
- char * temp = (char *)malloc (strlen (path )+strlen (_mountpoint)+1 );
202
+ char * temp = (char *)malloc (strlen (fpath )+strlen (_mountpoint)+1 );
203
203
if (!temp) {
204
204
log_e (" malloc failed" );
205
205
return false ;
206
206
}
207
- sprintf (temp," %s%s" , _mountpoint, path );
207
+ sprintf (temp," %s%s" , _mountpoint, fpath );
208
208
auto rc = ::rmdir (temp);
209
209
free (temp);
210
210
return rc == 0 ;
@@ -213,23 +213,23 @@ bool VFSImpl::rmdir(const char *path)
213
213
214
214
215
215
216
- VFSFileImpl::VFSFileImpl (VFSImpl* fs, const char * path , const char * mode)
216
+ VFSFileImpl::VFSFileImpl (VFSImpl* fs, const char * fpath , const char * mode)
217
217
: _fs(fs)
218
218
, _f(NULL )
219
219
, _d(NULL )
220
220
, _path(NULL )
221
221
, _isDirectory(false )
222
222
, _written(false )
223
223
{
224
- char * temp = (char *)malloc (strlen (path )+strlen (_fs->_mountpoint )+1 );
224
+ char * temp = (char *)malloc (strlen (fpath )+strlen (_fs->_mountpoint )+1 );
225
225
if (!temp) {
226
226
return ;
227
227
}
228
- sprintf (temp," %s%s" , _fs->_mountpoint , path );
228
+ sprintf (temp," %s%s" , _fs->_mountpoint , fpath );
229
229
230
- _path = strdup (path );
230
+ _path = strdup (fpath );
231
231
if (!_path) {
232
- log_e (" strdup(%s) failed" , path );
232
+ log_e (" strdup(%s) failed" , fpath );
233
233
free (temp);
234
234
return ;
235
235
}
@@ -377,11 +377,16 @@ size_t VFSFileImpl::size() const
377
377
return _stat.st_size ;
378
378
}
379
379
380
- const char * VFSFileImpl::name () const
380
+ const char * VFSFileImpl::path () const
381
381
{
382
382
return (const char *) _path;
383
383
}
384
384
385
+ const char * VFSFileImpl::name () const
386
+ {
387
+ return pathToFileName (path ());
388
+ }
389
+
385
390
// to implement
386
391
boolean VFSFileImpl::isDirectory (void )
387
392
{
0 commit comments