Software Update with apply the settings (Part11)

- Deletelist added to delete files or directories from image
- Files/Directories are marked by a prefixed '~' in the settingsupdate.conf
- Rework readBackupList()


Origin commit data
------------------
Branch: ni/coolstream
Commit: 1ca7ced674
Author: Michael Liebmann <tuxcode.bbg@gmail.com>
Date: 2012-11-12 (Mon, 12 Nov 2012)

Origin message was:
------------------
* Software Update with apply the settings (Part11)

- Deletelist added to delete files or directories from image
- Files/Directories are marked by a prefixed '~' in the settingsupdate.conf
- Rework readBackupList()


------------------
This commit was generated by Migit
This commit is contained in:
Michael Liebmann
2012-11-12 16:13:11 +01:00
parent 21a4195103
commit 48abdf965e
7 changed files with 132 additions and 51 deletions

View File

@@ -73,7 +73,9 @@ CExtUpdate::CExtUpdate()
fLogfile = "/tmp/update.log";
mountPkt = "/tmp/image_mount";
FileHelpers = NULL;
BlackList.clear();
copyList.clear();
blackList.clear();
deleteList.clear();
}
CExtUpdate::~CExtUpdate()
@@ -82,7 +84,9 @@ CExtUpdate::~CExtUpdate()
delete[] MTDBuf;
if(FileHelpers)
delete[] FileHelpers;
BlackList.clear();
copyList.clear();
blackList.clear();
deleteList.clear();
}
CExtUpdate* CExtUpdate::getInstance()
@@ -120,6 +124,7 @@ bool CExtUpdate::ErrorReset(bool modus, const std::string & msg1, const std::str
}
if(hintBox)
hintBox->hide();
sync();
return false;
}
@@ -339,6 +344,7 @@ bool CExtUpdate::applySettings()
if(hintBox)
hintBox->hide();
sync();
return true;
}
@@ -399,6 +405,40 @@ bool CExtUpdate::copyFileList(const std::string & fileList, const std::string &
return true;
}
bool CExtUpdate::deleteFileList(const std::string & fileList)
{
Wildcard = "";
struct dirent **namelist;
std::string fList = fileList;
static struct stat FileInfo;
size_t pos = fileList.find_last_of("/");
fList = fileList.substr(0, pos);
Wildcard = fileList.substr(pos+1);
int n = scandir(fList.c_str(), &namelist, fileSelect, 0);
if (n > 0) {
while (n--) {
std::string dName = namelist[n]->d_name;
if (lstat((fList+"/"+dName).c_str(), &FileInfo) != -1) {
if (S_ISDIR(FileInfo.st_mode)) {
// Directory
WRITE_UPDATE_LOG("delete directory: %s\n", (fList+"/"+dName).c_str());
FileHelpers->removeDir((fList+"/"+dName).c_str());
}
else if (S_ISREG(FileInfo.st_mode)) {
// File
WRITE_UPDATE_LOG("delete file: %s\n", (fList+"/"+dName).c_str());
unlink((fList+"/"+dName).c_str());
}
}
free(namelist[n]);
}
free(namelist);
}
return true;
}
bool CExtUpdate::findConfigEntry(std::string & line, std::string find)
{
if (line.find("#:" + find + "=") == 0) {
@@ -430,7 +470,7 @@ bool CExtUpdate::readConfig(const std::string & line)
bool CExtUpdate::isBlacklistEntry(const std::string & file)
{
for(vector<std::string>::iterator it = BlackList.begin(); it != BlackList.end(); ++it) {
for(vector<std::string>::iterator it = blackList.begin(); it != blackList.end(); ++it) {
if (*it == file) {
DBG_MSG("BlacklistEntry %s\n", (*it).c_str());
WRITE_UPDATE_LOG("BlacklistEntry: %s\n", (*it).c_str());
@@ -440,6 +480,20 @@ bool CExtUpdate::isBlacklistEntry(const std::string & file)
return false;
}
bool CExtUpdate::checkSpecialFolders(std::string line, bool copy)
{
if ((line == "/") || (line == "/*") || (line == "/*.*") || (line.find("/dev") == 0) || (line.find("/proc") == 0) ||
(line.find("/sys") == 0) || (line.find("/mnt") == 0) || (line.find("/tmp") == 0)) {
char buf[PATH_MAX];
neutrino_locale_t msg = (copy) ? LOCALE_FLASHUPDATE_UPDATE_WITH_SETTINGS_SKIPPED : LOCALE_FLASHUPDATE_UPDATE_WITH_SETTINGS_DEL_SKIPPED;
snprintf(buf, sizeof(buf), g_Locale->getText(msg), line.c_str());
WRITE_UPDATE_LOG("%s%s", buf, "\n");
ShowMsgUTF(LOCALE_MESSAGEBOX_INFO, buf, CMessageBox::mbrOk, CMessageBox::mbOk, NEUTRINO_ICON_INFO);
return true;
}
return false;
}
bool CExtUpdate::readBackupList(const std::string & dstPath)
{
char buf[PATH_MAX];
@@ -470,37 +524,18 @@ bool CExtUpdate::readBackupList(const std::string & dstPath)
size_t pos;
std::string line;
// read blacklist
BlackList.clear();
while(fgets(buf, sizeof(buf), f1) != NULL) {
line = buf;
line = trim(line);
// ignore comments
if (line.find_first_of("#") == 0)
continue;
pos = line.find_first_of("#");
if (pos != std::string::npos) {
line = line.substr(0, pos);
line = trim(line);
}
// find blacklist entry
if (line.find_first_of("-") == 0) {
line = line.substr(1);
if ((line.length() > 1) && (lstat(line.c_str(), &FileInfo) != -1)) {
if (S_ISREG(FileInfo.st_mode))
BlackList.push_back(line);
}
}
}
// read backuplist
fseek(f1, 0, SEEK_SET);
// read blacklist and config vars
copyList.clear();
blackList.clear();
deleteList.clear();
while(fgets(buf, sizeof(buf), f1) != NULL) {
std::string tmpLine;
line = buf;
line = trim(line);
// ignore comments
if (line.find_first_of("#") == 0) {
if (line.find_first_of(":") == 1) { // config vars
// config vars
if (line.find_first_of(":") == 1) {
if (line.length() > 1)
readConfig(line);
}
@@ -511,27 +546,39 @@ bool CExtUpdate::readBackupList(const std::string & dstPath)
line = line.substr(0, pos);
line = trim(line);
}
// '+' add entry = default
if (line.find_first_of("+") == 0)
line = line.substr(1);
// '-' blacklist entry
if (line.find_first_of("-") == 0)
continue;
// Entry '~' (delete) ignore currently still
if (line.find_first_of("~") == 0)
continue;
// special folders
else if ((line == "/") || (line == "/*") || (line == "/*.*") || (line.find("/dev") == 0) || (line.find("/proc") == 0) ||
(line.find("/sys") == 0) || (line.find("/mnt") == 0) || (line.find("/tmp") == 0)) {
snprintf(buf, sizeof(buf), g_Locale->getText(LOCALE_FLASHUPDATE_UPDATE_WITH_SETTINGS_SKIPPED), line.c_str());
WRITE_UPDATE_LOG("%s%s", buf, "\n");
ShowMsgUTF(LOCALE_MESSAGEBOX_INFO, buf, CMessageBox::mbrOk, CMessageBox::mbOk, NEUTRINO_ICON_INFO);
continue;
// find blackList entry
if (line.find_first_of("-") == 0) {
tmpLine = line.substr(1);
if ((tmpLine.length() > 1) && (lstat(tmpLine.c_str(), &FileInfo) != -1)) {
if (S_ISREG(FileInfo.st_mode))
blackList.push_back(tmpLine);
}
}
// find deleteList entry
else if (line.find_first_of("~") == 0) {
tmpLine = line.substr(1);
if (checkSpecialFolders(tmpLine, false))
continue;
tmpLine = dstPath + tmpLine;
if (line.length() > 2)
deleteList.push_back(tmpLine);
}
// find copyList entry
else {
tmpLine = (line.find_first_of("+") == 0) ? line.substr(1) : line; // '+' add entry = default
if (checkSpecialFolders(tmpLine, true))
continue;
if (tmpLine.length() > 1)
copyList.push_back(tmpLine);
}
}
fclose(f1);
// read copyList
vector<std::string>::iterator it;
for(it = copyList.begin(); it != copyList.end(); ++it) {
line = *it;
line = trim(line);
// remove '/' from line end
size_t len = line.length();
pos = line.find_last_of("/");
@@ -573,8 +620,29 @@ bool CExtUpdate::readBackupList(const std::string & dstPath)
}
}
fclose(f1);
// read DeleteList
for(it = deleteList.begin(); it != deleteList.end(); ++it) {
line = *it;
if (lstat(line.c_str(), &FileInfo) != -1) {
if ((line.find("*") != std::string::npos) || (line.find("?") != std::string::npos)) {
// Wildcards
WRITE_UPDATE_LOG("delete file list: %s\n", line.c_str());
deleteFileList(line.c_str());
}
else if (S_ISREG(FileInfo.st_mode)) {
// File
WRITE_UPDATE_LOG("delete file: %s\n", line.c_str());
unlink(line.c_str());
}
else if (S_ISDIR(FileInfo.st_mode)){
// Directory
WRITE_UPDATE_LOG("delete directory: %s\n", line.c_str());
FileHelpers->removeDir(line.c_str());
}
}
}
sync();
return true;
}