@@ -70,6 +70,8 @@ class SdSpiConfig {
70
70
class File : public Stream {
71
71
public:
72
72
bool isOpen () {
73
+ if (filename == " " ) return false ;
74
+ if (is_dir) return true ;
73
75
bool result = file.is_open ();
74
76
return result;
75
77
}
@@ -85,8 +87,12 @@ class File : public Stream {
85
87
is_dir = true ;
86
88
size_bytes = 0 ;
87
89
#ifdef USE_FILESYSTEM
88
- dir_path = std::filesystem::path (filename);
89
- iterator = std::filesystem::directory_iterator ({dir_path});
90
+ // prevent authorization exceptions
91
+ try {
92
+ dir_path = std::filesystem::path (filename);
93
+ iterator = std::filesystem::directory_iterator ({dir_path});
94
+ } catch (...) {
95
+ }
90
96
#endif
91
97
return true ;
92
98
} else {
@@ -131,10 +137,17 @@ class File : public Stream {
131
137
return is_dir;
132
138
}
133
139
bool openNext (File &dir, int flags = O_RDONLY) {
140
+ if (!*this ) return false ;
141
+
142
+ // if (pos == 0) {
143
+ // dir_path = std::filesystem::path(filename);
144
+ // iterator = std::filesystem::directory_iterator({dir_path});
145
+ // }
146
+ // pos++;
134
147
#ifdef USE_FILESYSTEM
135
- if (dir. isDir () && dir. iterator != end (dir. iterator )) {
136
- std::filesystem::directory_entry entry = *dir. iterator ++;
137
- return open (entry.path ().c_str (), flags);
148
+ if (iterator != end (iterator)) {
149
+ std::filesystem::directory_entry entry = *iterator++;
150
+ return dir. open (entry.path ().c_str (), flags);
138
151
}
139
152
#endif
140
153
return false ;
@@ -169,9 +182,9 @@ class File : public Stream {
169
182
protected:
170
183
std::fstream file;
171
184
size_t size_bytes = 0 ;
172
- bool is_dir;
185
+ bool is_dir = false ;
173
186
int pos = 0 ;
174
- std::string filename;
187
+ std::string filename = " " ;
175
188
struct stat info;
176
189
177
190
#ifdef USE_FILESYSTEM
@@ -180,7 +193,7 @@ class File : public Stream {
180
193
#endif
181
194
182
195
std::ios_base::openmode toMode (int flags) {
183
- return (std::ios_base::openmode) flags;
196
+ return (std::ios_base::openmode)flags;
184
197
}
185
198
};
186
199
@@ -191,7 +204,7 @@ class File : public Stream {
191
204
class SdFat {
192
205
public:
193
206
bool begin (int cs = SS, int speed = 0 ) { return true ; }
194
-
207
+
195
208
bool begin (SdSpiConfig &cfg) { return true ; }
196
209
197
210
void errorHalt (const char *msg) {
@@ -220,12 +233,12 @@ class SdFat {
220
233
uint64_t totalBytes () {
221
234
std::error_code ec;
222
235
const std::filesystem::space_info si = std::filesystem::space (" /home" , ec);
223
- return si.capacity ;
236
+ return si.capacity ;
224
237
}
225
238
uint64_t usedBytes () {
226
239
std::error_code ec;
227
240
const std::filesystem::space_info si = std::filesystem::space (" /home" , ec);
228
- return si.capacity - si.available ;
241
+ return si.capacity - si.available ;
229
242
}
230
243
};
231
244
0 commit comments