mirror of
https://github.com/jomjol/AI-on-the-edge-device.git
synced 2025-12-09 13:06:54 +03:00
Create folders as needed (#2056)
* allow longer file paths * create folders as needed --------- Co-authored-by: CaCO3 <caco@ruinelli.ch>
This commit is contained in:
@@ -996,8 +996,12 @@ std::string unzip_new(std::string _in_zip_file, std::string _target_zip, std::st
|
|||||||
|
|
||||||
ESP_LOGI(TAG, "Filename to extract: %s, Zwischenfilename: %s", zw.c_str(), filename_zw.c_str());
|
ESP_LOGI(TAG, "Filename to extract: %s, Zwischenfilename: %s", zw.c_str(), filename_zw.c_str());
|
||||||
|
|
||||||
|
std::string folder = filename_zw.substr(0, filename_zw.find_last_of('/'));
|
||||||
|
MakeDir(folder);
|
||||||
|
|
||||||
// extrahieren in zwischendatei
|
// extrahieren in zwischendatei
|
||||||
DeleteFile(filename_zw);
|
DeleteFile(filename_zw);
|
||||||
|
|
||||||
FILE* fpTargetFile = fopen(filename_zw.c_str(), "wb");
|
FILE* fpTargetFile = fopen(filename_zw.c_str(), "wb");
|
||||||
uint writtenbytes = fwrite(p, 1, (uint)uncomp_size, fpTargetFile);
|
uint writtenbytes = fwrite(p, 1, (uint)uncomp_size, fpTargetFile);
|
||||||
fclose(fpTargetFile);
|
fclose(fpTargetFile);
|
||||||
|
|||||||
@@ -224,15 +224,50 @@ void FindReplace(std::string& line, std::string& oldString, std::string& newStri
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool MakeDir(std::string _what)
|
/**
|
||||||
|
* Create a folder and its parent folders as needed
|
||||||
|
*/
|
||||||
|
bool MakeDir(std::string path)
|
||||||
{
|
{
|
||||||
int mk_ret = mkdir(_what.c_str(), 0775);
|
std::string parent;
|
||||||
if (mk_ret)
|
|
||||||
{
|
LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "Creating folder " + path + "...");
|
||||||
ESP_LOGD(TAG, "error with mkdir %s ret %d", _what.c_str(), mk_ret);
|
|
||||||
return false;
|
bool bSuccess = false;
|
||||||
|
int nRC = ::mkdir( path.c_str(), 0775 );
|
||||||
|
if( nRC == -1 )
|
||||||
|
{
|
||||||
|
switch( errno ) {
|
||||||
|
case ENOENT:
|
||||||
|
//parent didn't exist, try to create it
|
||||||
|
parent = path.substr(0, path.find_last_of('/'));
|
||||||
|
LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "Need to create parent folder first: " + parent);
|
||||||
|
if(MakeDir(parent)) {
|
||||||
|
//Now, try to create again.
|
||||||
|
bSuccess = 0 == ::mkdir( path.c_str(), 0775 );
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Failed to create parent folder: " + parent);
|
||||||
|
bSuccess = false;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case EEXIST:
|
||||||
|
//Done!
|
||||||
|
bSuccess = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Failed to create folder: " + path);
|
||||||
|
bSuccess = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
bSuccess = true;
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
|
return bSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user