1616
1717using namespace fs ;
1818
19- FileImplPtr VFSImpl::open (const char * path , const char * mode)
19+ FileImplPtr VFSImpl::open (const char * fpath , const char * mode)
2020{
2121 if (!_mountpoint) {
2222 log_e (" File system is not mounted" );
2323 return FileImplPtr ();
2424 }
2525
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 );
2828 return FileImplPtr ();
2929 }
3030
31- char * temp = (char *)malloc (strlen (path )+strlen (_mountpoint)+2 );
31+ char * temp = (char *)malloc (strlen (fpath )+strlen (_mountpoint)+2 );
3232 if (!temp) {
3333 log_e (" malloc failed" );
3434 return FileImplPtr ();
3535 }
3636
37- sprintf (temp," %s%s" , _mountpoint, path );
37+ sprintf (temp," %s%s" , _mountpoint, fpath );
3838
3939 struct stat st;
4040 // file lound
4141 if (!stat (temp, &st)) {
4242 free (temp);
4343 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);
4545 }
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 );
4747 return FileImplPtr ();
4848 }
4949
5050 // file not found but mode permits creation
5151 if (mode && mode[0 ] != ' r' ) {
5252 free (temp);
53- return std::make_shared<VFSFileImpl>(this , path , mode);
53+ return std::make_shared<VFSFileImpl>(this , fpath , mode);
5454 }
5555
5656 // try to open this as directory (might be mount point)
5757 DIR * d = opendir (temp);
5858 if (d) {
5959 closedir (d);
6060 free (temp);
61- return std::make_shared<VFSFileImpl>(this , path , mode);
61+ return std::make_shared<VFSFileImpl>(this , fpath , mode);
6262 }
6363
6464 log_e (" %s does not exist" , temp);
6565 free (temp);
6666 return FileImplPtr ();
6767}
6868
69- bool VFSImpl::exists (const char * path )
69+ bool VFSImpl::exists (const char * fpath )
7070{
7171 if (!_mountpoint) {
7272 log_e (" File system is not mounted" );
7373 return false ;
7474 }
7575
76- VFSFileImpl f (this , path , " r" );
76+ VFSFileImpl f (this , fpath , " r" );
7777 if (f) {
7878 f.close ();
7979 return true ;
@@ -115,69 +115,69 @@ bool VFSImpl::rename(const char* pathFrom, const char* pathTo)
115115 return rc == 0 ;
116116}
117117
118- bool VFSImpl::remove (const char * path )
118+ bool VFSImpl::remove (const char * fpath )
119119{
120120 if (!_mountpoint) {
121121 log_e (" File system is not mounted" );
122122 return false ;
123123 }
124124
125- if (!path || path [0 ] != ' /' ) {
125+ if (!fpath || fpath [0 ] != ' /' ) {
126126 log_e (" bad arguments" );
127127 return false ;
128128 }
129129
130- VFSFileImpl f (this , path , " r" );
130+ VFSFileImpl f (this , fpath , " r" );
131131 if (!f || f.isDirectory ()) {
132132 if (f) {
133133 f.close ();
134134 }
135- log_e (" %s does not exists or is directory" , path );
135+ log_e (" %s does not exists or is directory" , fpath );
136136 return false ;
137137 }
138138 f.close ();
139139
140- char * temp = (char *)malloc (strlen (path )+strlen (_mountpoint)+1 );
140+ char * temp = (char *)malloc (strlen (fpath )+strlen (_mountpoint)+1 );
141141 if (!temp) {
142142 log_e (" malloc failed" );
143143 return false ;
144144 }
145- sprintf (temp," %s%s" , _mountpoint, path );
145+ sprintf (temp," %s%s" , _mountpoint, fpath );
146146 auto rc = unlink (temp);
147147 free (temp);
148148 return rc == 0 ;
149149}
150150
151- bool VFSImpl::mkdir (const char *path )
151+ bool VFSImpl::mkdir (const char *fpath )
152152{
153153 if (!_mountpoint) {
154154 log_e (" File system is not mounted" );
155155 return false ;
156156 }
157157
158- VFSFileImpl f (this , path , " r" );
158+ VFSFileImpl f (this , fpath , " r" );
159159 if (f && f.isDirectory ()) {
160160 f.close ();
161- // log_w("%s already exists", path );
161+ // log_w("%s already exists", fpath );
162162 return true ;
163163 } else if (f) {
164164 f.close ();
165- log_e (" %s is a file" , path );
165+ log_e (" %s is a file" , fpath );
166166 return false ;
167167 }
168168
169- char * temp = (char *)malloc (strlen (path )+strlen (_mountpoint)+1 );
169+ char * temp = (char *)malloc (strlen (fpath )+strlen (_mountpoint)+1 );
170170 if (!temp) {
171171 log_e (" malloc failed" );
172172 return false ;
173173 }
174- sprintf (temp," %s%s" , _mountpoint, path );
174+ sprintf (temp," %s%s" , _mountpoint, fpath );
175175 auto rc = ::mkdir (temp, ACCESSPERMS);
176176 free (temp);
177177 return rc == 0 ;
178178}
179179
180- bool VFSImpl::rmdir (const char *path )
180+ bool VFSImpl::rmdir (const char *fpath )
181181{
182182 if (!_mountpoint) {
183183 log_e (" File system is not mounted" );
@@ -189,22 +189,22 @@ bool VFSImpl::rmdir(const char *path)
189189 return false ;
190190 }
191191
192- VFSFileImpl f (this , path , " r" );
192+ VFSFileImpl f (this , fpath , " r" );
193193 if (!f || !f.isDirectory ()) {
194194 if (f) {
195195 f.close ();
196196 }
197- log_e (" %s does not exists or is a file" , path );
197+ log_e (" %s does not exists or is a file" , fpath );
198198 return false ;
199199 }
200200 f.close ();
201201
202- char * temp = (char *)malloc (strlen (path )+strlen (_mountpoint)+1 );
202+ char * temp = (char *)malloc (strlen (fpath )+strlen (_mountpoint)+1 );
203203 if (!temp) {
204204 log_e (" malloc failed" );
205205 return false ;
206206 }
207- sprintf (temp," %s%s" , _mountpoint, path );
207+ sprintf (temp," %s%s" , _mountpoint, fpath );
208208 auto rc = ::rmdir (temp);
209209 free (temp);
210210 return rc == 0 ;
@@ -213,23 +213,23 @@ bool VFSImpl::rmdir(const char *path)
213213
214214
215215
216- VFSFileImpl::VFSFileImpl (VFSImpl* fs, const char * path , const char * mode)
216+ VFSFileImpl::VFSFileImpl (VFSImpl* fs, const char * fpath , const char * mode)
217217 : _fs(fs)
218218 , _f(NULL )
219219 , _d(NULL )
220220 , _path(NULL )
221221 , _isDirectory(false )
222222 , _written(false )
223223{
224- char * temp = (char *)malloc (strlen (path )+strlen (_fs->_mountpoint )+1 );
224+ char * temp = (char *)malloc (strlen (fpath )+strlen (_fs->_mountpoint )+1 );
225225 if (!temp) {
226226 return ;
227227 }
228- sprintf (temp," %s%s" , _fs->_mountpoint , path );
228+ sprintf (temp," %s%s" , _fs->_mountpoint , fpath );
229229
230- _path = strdup (path );
230+ _path = strdup (fpath );
231231 if (!_path) {
232- log_e (" strdup(%s) failed" , path );
232+ log_e (" strdup(%s) failed" , fpath );
233233 free (temp);
234234 return ;
235235 }
@@ -377,11 +377,16 @@ size_t VFSFileImpl::size() const
377377 return _stat.st_size ;
378378}
379379
380- const char * VFSFileImpl::name () const
380+ const char * VFSFileImpl::path () const
381381{
382382 return (const char *) _path;
383383}
384384
385+ const char * VFSFileImpl::name () const
386+ {
387+ return pathToFileName (path ());
388+ }
389+
385390// to implement
386391boolean VFSFileImpl::isDirectory (void )
387392{
0 commit comments