mirror of
https://github.com/tuxbox-fork-migrations/recycled-ni-neutrino.git
synced 2025-08-27 23:42:51 +02:00
CFileHelpers::createDir: Fix return value
Signed-off-by: M. Liebmann <tuxcode.bbg@gmail.com>
Origin commit data
------------------
Commit: 0180d59111
Author: [CST] Bas <bas@coolstreamtech.com>
Date: 2015-10-18 (Sun, 18 Oct 2015)
This commit is contained in:
committed by
Michael Liebmann
parent
54e2034f30
commit
ad6e938a09
@@ -161,10 +161,10 @@ int CThemes::Show()
|
|||||||
CKeyboardInput nameInput(LOCALE_COLORTHEMEMENU_NAME, &file_name);
|
CKeyboardInput nameInput(LOCALE_COLORTHEMEMENU_NAME, &file_name);
|
||||||
CMenuForwarder *m1 = new CMenuForwarder(LOCALE_COLORTHEMEMENU_SAVE, true , NULL, &nameInput, NULL, CRCInput::RC_green);
|
CMenuForwarder *m1 = new CMenuForwarder(LOCALE_COLORTHEMEMENU_SAVE, true , NULL, &nameInput, NULL, CRCInput::RC_green);
|
||||||
|
|
||||||
if (CFileHelpers::createDir(THEMESDIR_VAR) && errno != EEXIST) {
|
if (!CFileHelpers::createDir(THEMESDIR_VAR)) {
|
||||||
printf("[neutrino theme] error creating %s\n", THEMESDIR_VAR);
|
printf("[neutrino theme] error creating %s\n", THEMESDIR_VAR);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (access(THEMESDIR_VAR, F_OK) == 0 ) {
|
if (access(THEMESDIR_VAR, F_OK) == 0 ) {
|
||||||
themes.addItem(GenericMenuSeparatorLine);
|
themes.addItem(GenericMenuSeparatorLine);
|
||||||
themes.addItem(m1);
|
themes.addItem(m1);
|
||||||
@@ -365,7 +365,7 @@ void CThemes::move_userDir()
|
|||||||
{
|
{
|
||||||
if (access(USERDIR, F_OK) == 0)
|
if (access(USERDIR, F_OK) == 0)
|
||||||
{
|
{
|
||||||
if (CFileHelpers::createDir(THEMESDIR_VAR) && errno != EEXIST)
|
if (!CFileHelpers::createDir(THEMESDIR_VAR))
|
||||||
{
|
{
|
||||||
printf("[neutrino theme] error creating %s\n", THEMESDIR_VAR);
|
printf("[neutrino theme] error creating %s\n", THEMESDIR_VAR);
|
||||||
return;
|
return;
|
||||||
|
@@ -629,11 +629,9 @@ bool CFileHelpers::copyDir(const char *Src, const char *Dst, bool backupMode)
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// directory
|
// directory
|
||||||
if (createDir(Dst, FileInfo.st_mode & 0x0FFF) == false) {
|
if (!createDir(Dst, FileInfo.st_mode & 0x0FFF)) {
|
||||||
if (errno != EEXIST) {
|
closedir(Directory);
|
||||||
closedir(Directory);
|
return false;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -676,25 +674,34 @@ bool CFileHelpers::copyDir(const char *Src, const char *Dst, bool backupMode)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CFileHelpers::createDir(string& Dir, mode_t mode)
|
// returns: true - success.
|
||||||
|
// false - errno is set
|
||||||
|
bool CFileHelpers::createDir(string& Dir, mode_t mode)
|
||||||
{
|
{
|
||||||
struct stat st;
|
|
||||||
int res = 0;
|
int res = 0;
|
||||||
for(string::iterator iter = Dir.begin() ; iter != Dir.end();) {
|
for(string::iterator iter = Dir.begin() ; iter != Dir.end();) {
|
||||||
string::iterator newIter = find(iter, Dir.end(), '/' );
|
string::iterator newIter = find(iter, Dir.end(), '/' );
|
||||||
string newPath = string( Dir.begin(), newIter );
|
string newPath = string( Dir.begin(), newIter );
|
||||||
if( !newPath.empty() && stat(newPath.c_str(), &st) != 0) {
|
if(!newPath.empty() && !file_exists(newPath.c_str())) {
|
||||||
res = mkdir( newPath.c_str(), mode);
|
res = mkdir( newPath.c_str(), mode);
|
||||||
if (errno == EEXIST)
|
if (res == -1) {
|
||||||
res = 0;
|
if (errno == EEXIST) {
|
||||||
if(res != 0)
|
res = 0;
|
||||||
dprintf(DEBUG_NORMAL, "[CFileHelpers %s] creating directory %s: %s\n", __func__, newPath.c_str(), strerror(errno));
|
} else {
|
||||||
|
// We can assume that if an error
|
||||||
|
// occured, following will fail too,
|
||||||
|
// so break here.
|
||||||
|
dprintf(DEBUG_NORMAL, "[CFileHelpers %s] creating directory %s: %s\n", __func__, newPath.c_str(), strerror(errno));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
iter = newIter;
|
iter = newIter;
|
||||||
if(newIter != Dir.end())
|
if(newIter != Dir.end())
|
||||||
++ iter;
|
++ iter;
|
||||||
}
|
}
|
||||||
return res;
|
|
||||||
|
return (res == 0 ? true : false);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CFileHelpers::removeDir(const char *Dir)
|
bool CFileHelpers::removeDir(const char *Dir)
|
||||||
|
@@ -88,8 +88,8 @@ class CFileHelpers
|
|||||||
|
|
||||||
bool copyFile(const char *Src, const char *Dst, mode_t mode);
|
bool copyFile(const char *Src, const char *Dst, mode_t mode);
|
||||||
bool copyDir(const char *Src, const char *Dst, bool backupMode=false);
|
bool copyDir(const char *Src, const char *Dst, bool backupMode=false);
|
||||||
static int createDir(std::string& Dir, mode_t mode = 755);
|
static bool createDir(std::string& Dir, mode_t mode = 755);
|
||||||
static int createDir(const char *Dir, mode_t mode = 755){std::string dir = std::string(Dir);return createDir(dir, mode);}
|
static bool createDir(const char *Dir, mode_t mode = 755){std::string dir = std::string(Dir);return createDir(dir, mode);}
|
||||||
static bool removeDir(const char *Dir);
|
static bool removeDir(const char *Dir);
|
||||||
static uint64_t getDirSize(const char *dir);
|
static uint64_t getDirSize(const char *dir);
|
||||||
static uint64_t getDirSize(const std::string& dir){return getDirSize(dir.c_str());};
|
static uint64_t getDirSize(const std::string& dir){return getDirSize(dir.c_str());};
|
||||||
|
Reference in New Issue
Block a user