@@ -38,6 +38,16 @@ static std::vector<uint8_t> s_spiffsWorkBuf;
38
38
static std::vector<uint8_t > s_spiffsFds;
39
39
static std::vector<uint8_t > s_spiffsCache;
40
40
41
+ static int s_debugLevel = 0 ;
42
+ static bool s_addAllFiles;
43
+
44
+ // Unless -a flag is given, these files/directories will not be included into the image
45
+ static const char * ignored_file_names[] = {
46
+ " .DS_Store" ,
47
+ " .git" ,
48
+ " .gitignore" ,
49
+ " .gitmodules"
50
+ };
41
51
42
52
static s32_t api_spiffs_read (u32_t addr, u32_t size, u8_t *dst){
43
53
memcpy (dst, &s_flashmem[0 ] + addr, size);
@@ -55,7 +65,6 @@ static s32_t api_spiffs_erase(u32_t addr, u32_t size){
55
65
}
56
66
57
67
58
- int g_debugLevel = 0 ;
59
68
60
69
61
70
// implementation
@@ -121,7 +130,7 @@ int addFile(char* name, const char* path) {
121
130
size_t size = ftell (src);
122
131
fseek (src, 0 , SEEK_SET);
123
132
124
- if (g_debugLevel > 0 ) {
133
+ if (s_debugLevel > 0 ) {
125
134
std::cout << " file size: " << size << std::endl;
126
135
}
127
136
@@ -146,7 +155,7 @@ int addFile(char* name, const char* path) {
146
155
}
147
156
std::cerr << std::endl;
148
157
149
- if (g_debugLevel > 0 ) {
158
+ if (s_debugLevel > 0 ) {
150
159
std::cout << " data left: " << left << std::endl;
151
160
}
152
161
@@ -181,6 +190,21 @@ int addFiles(const char* dirname, const char* subPath) {
181
190
continue ;
182
191
}
183
192
193
+ if (!s_addAllFiles) {
194
+ bool skip = false ;
195
+ size_t ignored_file_names_count = sizeof (ignored_file_names) / sizeof (ignored_file_names[0 ]);
196
+ for (size_t i = 0 ; i < ignored_file_names_count; ++i) {
197
+ if (strcmp (ent->d_name , ignored_file_names[i]) == 0 ) {
198
+ std::cerr << " skipping " << ent->d_name << std::endl;
199
+ skip = true ;
200
+ break ;
201
+ }
202
+ }
203
+ if (skip) {
204
+ continue ;
205
+ }
206
+ }
207
+
184
208
std::string fullpath = dirPath;
185
209
fullpath += ent->d_name ;
186
210
struct stat path_stat;
@@ -217,7 +241,7 @@ int addFiles(const char* dirname, const char* subPath) {
217
241
if (addFile ((char *)filepath.c_str (), fullpath.c_str ()) != 0 ) {
218
242
std::cerr << " error adding file!" << std::endl;
219
243
error = true ;
220
- if (g_debugLevel > 0 ) {
244
+ if (s_debugLevel > 0 ) {
221
245
std::cout << std::endl;
222
246
}
223
247
break ;
@@ -516,20 +540,22 @@ void processArgs(int argc, const char** argv) {
516
540
TCLAP::ValueArg<int > imageSizeArg ( " s" , " size" , " fs image size, in bytes" , false , 0x10000 , " number" );
517
541
TCLAP::ValueArg<int > pageSizeArg ( " p" , " page" , " fs page size, in bytes" , false , 256 , " number" );
518
542
TCLAP::ValueArg<int > blockSizeArg ( " b" , " block" , " fs block size, in bytes" , false , 4096 , " number" );
543
+ TCLAP::SwitchArg addAllFilesArg ( " a" , " all-files" , " when creating an image, include files which are normally ignored; currently only applies to '.DS_Store' files and '.git' directories" , false );
519
544
TCLAP::ValueArg<int > debugArg ( " d" , " debug" , " Debug level. 0 means no debug output." , false , 0 , " 0-5" );
520
545
521
546
cmd.add ( imageSizeArg );
522
547
cmd.add ( pageSizeArg );
523
548
cmd.add ( blockSizeArg );
524
- cmd.add (debugArg);
549
+ cmd.add ( addAllFilesArg );
550
+ cmd.add ( debugArg );
525
551
std::vector<TCLAP::Arg*> args = {&packArg, &unpackArg, &listArg, &visualizeArg};
526
552
cmd.xorAdd ( args );
527
553
cmd.add ( outNameArg );
528
554
cmd.parse ( argc, argv );
529
555
530
556
if (debugArg.getValue () > 0 ) {
531
557
std::cout << " Debug output enabled" << std::endl;
532
- g_debugLevel = debugArg.getValue ();
558
+ s_debugLevel = debugArg.getValue ();
533
559
}
534
560
535
561
if (packArg.isSet ()) {
@@ -548,6 +574,7 @@ void processArgs(int argc, const char** argv) {
548
574
s_imageSize = imageSizeArg.getValue ();
549
575
s_pageSize = pageSizeArg.getValue ();
550
576
s_blockSize = blockSizeArg.getValue ();
577
+ s_addAllFiles = addAllFilesArg.isSet ();
551
578
}
552
579
553
580
int main (int argc, const char * argv[]) {
0 commit comments