MCPcopy Create free account
hub / github.com/SmingHub/Sming / copySomeFiles

Function copySomeFiles

samples/Basic_IFS/app/application.cpp:352–399  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

350}
351
352void copySomeFiles()
353{
354 auto part = *Storage::findPartition(Storage::Partition::SubType::Data::fwfs);
355 if(!part) {
356 return;
357 }
358 auto fs = IFS::createFirmwareFilesystem(part);
359 if(fs == nullptr) {
360 return;
361 }
362 fs->mount();
363
364 IFS::Directory dir(fs);
365 if(!dir.open()) {
366 return;
367 }
368
369 while(dir.next()) {
370 auto& stat = dir.stat();
371 if(stat.isDir()) {
372 continue;
373 }
374 IFS::File src(fs);
375 auto filename = stat.name.c_str();
376 if(src.open(filename)) {
377 File dst;
378 if(dst.open(filename, File::CreateNewAlways | File::WriteOnly)) {
379 auto len =
380 src.readContent([&dst](const char* buffer, size_t size) -> int { return dst.write(buffer, size); });
381 (void)len;
382 debug_w("Wrote '%s', %d bytes", filename, len);
383
384 // Copy metadata
385 auto callback = [&](IFS::AttributeEnum& e) -> bool {
386 if(!dst.setAttribute(e.tag, e.buffer, e.size)) {
387 m_printf(_F("setAttribute(%s) failed: %s"), toString(e.tag).c_str(),
388 dst.getLastErrorString().c_str());
389 }
390 return true;
391 };
392 char buffer[1024];
393 src.enumAttributes(callback, buffer, sizeof(buffer));
394 } else {
395 debug_w("%s", dst.getLastErrorString().c_str());
396 }
397 }
398 }
399}
400
401bool isVolumeEmpty()
402{

Callers 1

fstestFunction · 0.85

Calls 9

m_printfFunction · 0.85
mountMethod · 0.80
findPartitionFunction · 0.50
toStringFunction · 0.50
openMethod · 0.45
nextMethod · 0.45
statMethod · 0.45
c_strMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected