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);
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
if (access(THEMESDIR_VAR, F_OK) == 0 ) {
|
||||
themes.addItem(GenericMenuSeparatorLine);
|
||||
themes.addItem(m1);
|
||||
@@ -365,7 +365,7 @@ void CThemes::move_userDir()
|
||||
{
|
||||
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);
|
||||
return;
|
||||
|
@@ -629,13 +629,11 @@ bool CFileHelpers::copyDir(const char *Src, const char *Dst, bool backupMode)
|
||||
}
|
||||
else {
|
||||
// directory
|
||||
if (createDir(Dst, FileInfo.st_mode & 0x0FFF) == false) {
|
||||
if (errno != EEXIST) {
|
||||
if (!createDir(Dst, FileInfo.st_mode & 0x0FFF)) {
|
||||
closedir(Directory);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// read directory
|
||||
while ((CurrentFile = readdir(Directory)) != NULL) {
|
||||
@@ -676,25 +674,34 @@ bool CFileHelpers::copyDir(const char *Src, const char *Dst, bool backupMode)
|
||||
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;
|
||||
for(string::iterator iter = Dir.begin() ; iter != Dir.end();) {
|
||||
string::iterator newIter = find(iter, Dir.end(), '/' );
|
||||
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);
|
||||
if (errno == EEXIST)
|
||||
if (res == -1) {
|
||||
if (errno == EEXIST) {
|
||||
res = 0;
|
||||
if(res != 0)
|
||||
} 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;
|
||||
if(newIter != Dir.end())
|
||||
++ iter;
|
||||
}
|
||||
return res;
|
||||
|
||||
return (res == 0 ? true : false);
|
||||
}
|
||||
|
||||
bool CFileHelpers::removeDir(const char *Dir)
|
||||
|
@@ -88,8 +88,8 @@ class CFileHelpers
|
||||
|
||||
bool copyFile(const char *Src, const char *Dst, mode_t mode);
|
||||
bool copyDir(const char *Src, const char *Dst, bool backupMode=false);
|
||||
static int 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(std::string& Dir, mode_t mode = 755);
|
||||
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 uint64_t getDirSize(const char *dir);
|
||||
static uint64_t getDirSize(const std::string& dir){return getDirSize(dir.c_str());};
|
||||
|
Reference in New Issue
Block a user