mirror of
https://github.com/tuxbox-fork-migrations/recycled-ni-neutrino.git
synced 2025-08-28 07:51:11 +02:00
system/helpers: remove mkdirhier(); gui/themes: use createDir()
This is a partial revert of picked commit67ea8dd650
. There were two methods, createDir() and mkdirhier() for the same purpose. We don't need it twice. btw: existing function createDir() fixed Origin commit data ------------------ Commit:1dcfc52a33
Author: Thilo Graf <dbt@novatux.de> Date: 2014-11-28 (Fri, 28 Nov 2014)
This commit is contained in:
@@ -163,8 +163,9 @@ 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 (mkdirhier(THEMEDIR_VAR) && errno != EEXIST) {
|
if (CFileHelpers::createDir(THEMEDIR_VAR) && errno != EEXIST) {
|
||||||
printf("[neutrino theme] error creating %s\n", THEMEDIR_VAR);
|
printf("[neutrino theme] error creating %s\n", THEMEDIR_VAR);
|
||||||
|
|
||||||
}
|
}
|
||||||
if (access(THEMEDIR_VAR, F_OK) == 0 ) {
|
if (access(THEMEDIR_VAR, F_OK) == 0 ) {
|
||||||
themes.addItem(GenericMenuSeparatorLine);
|
themes.addItem(GenericMenuSeparatorLine);
|
||||||
@@ -343,7 +344,7 @@ void CThemes::move_userDir()
|
|||||||
{
|
{
|
||||||
if (access(USERDIR, F_OK) == 0)
|
if (access(USERDIR, F_OK) == 0)
|
||||||
{
|
{
|
||||||
if (mkdirhier(THEMEDIR_VAR) && errno != EEXIST)
|
if (CFileHelpers::createDir(THEMEDIR_VAR) && errno != EEXIST)
|
||||||
{
|
{
|
||||||
printf("[neutrino theme] error creating %s\n", THEMEDIR_VAR);
|
printf("[neutrino theme] error creating %s\n", THEMEDIR_VAR);
|
||||||
return;
|
return;
|
||||||
|
@@ -38,12 +38,14 @@
|
|||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
#include <algorithm>
|
||||||
#include <mntent.h>
|
#include <mntent.h>
|
||||||
#include <linux/hdreg.h>
|
#include <linux/hdreg.h>
|
||||||
#include <linux/fs.h>
|
#include <linux/fs.h>
|
||||||
|
#include "debug.h"
|
||||||
#include <system/helpers.h>
|
#include <system/helpers.h>
|
||||||
#include <gui/update_ext.h>
|
#include <gui/update_ext.h>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
void mySleep(int sec) {
|
void mySleep(int sec) {
|
||||||
struct timeval timeout;
|
struct timeval timeout;
|
||||||
@@ -215,7 +217,7 @@ FILE* my_popen( pid_t& pid, const char *cmdstring, const char *type)
|
|||||||
}
|
}
|
||||||
return(fp);
|
return(fp);
|
||||||
}
|
}
|
||||||
|
#if 0
|
||||||
int mkdirhier(const char *pathname, mode_t mode)
|
int mkdirhier(const char *pathname, mode_t mode)
|
||||||
{
|
{
|
||||||
int res = -1;
|
int res = -1;
|
||||||
@@ -236,7 +238,7 @@ int mkdirhier(const char *pathname, mode_t mode)
|
|||||||
res = 0;
|
res = 0;
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
# endif
|
||||||
|
|
||||||
int safe_mkdir(const char * path)
|
int safe_mkdir(const char * path)
|
||||||
{
|
{
|
||||||
@@ -671,32 +673,25 @@ bool CFileHelpers::copyDir(const char *Src, const char *Dst, bool backupMode)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CFileHelpers::createDir(const char *Dir, mode_t mode)
|
int CFileHelpers::createDir(string& Dir, mode_t mode)
|
||||||
{
|
{
|
||||||
char dirPath[PATH_MAX];
|
struct stat st;
|
||||||
DIR *dir;
|
int res = 0;
|
||||||
if ((dir = opendir(Dir)) != NULL) {
|
for(string::iterator iter = Dir.begin() ; iter != Dir.end();) {
|
||||||
closedir(dir);
|
string::iterator newIter = find(iter, Dir.end(), '/' );
|
||||||
errno = EEXIST;
|
string newPath = string( Dir.begin(), newIter );
|
||||||
return false;
|
if( !newPath.empty() && stat(newPath.c_str(), &st) != 0) {
|
||||||
}
|
res = mkdir( newPath.c_str(), mode);
|
||||||
|
if (errno == EEXIST)
|
||||||
int ret = -1;
|
res = 0;
|
||||||
while (ret == -1) {
|
if(res != 0)
|
||||||
strcpy(dirPath, Dir);
|
dprintf(DEBUG_NORMAL, "[CFileHelpers %s] creating directory %s: %s\n", __func__, newPath.c_str(), strerror(errno));
|
||||||
ret = mkdir(dirPath, mode);
|
|
||||||
if ((errno == ENOENT) && (ret == -1)) {
|
|
||||||
char * pos = strrchr(dirPath,'/');
|
|
||||||
if (pos != NULL) {
|
|
||||||
pos[0] = '\0';
|
|
||||||
createDir(dirPath, mode);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
iter = newIter;
|
||||||
return !ret || (errno == EEXIST);
|
if(newIter != Dir.end())
|
||||||
|
++ iter;
|
||||||
}
|
}
|
||||||
errno = 0;
|
return res;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CFileHelpers::removeDir(const char *Dir)
|
bool CFileHelpers::removeDir(const char *Dir)
|
||||||
|
@@ -44,8 +44,8 @@ FILE* my_popen( pid_t& pid, const char *cmdstring, const char *type);
|
|||||||
|
|
||||||
int safe_mkdir(const char * path);
|
int safe_mkdir(const char * path);
|
||||||
inline int safe_mkdir(std::string path) { return safe_mkdir(path.c_str()); }
|
inline int safe_mkdir(std::string path) { return safe_mkdir(path.c_str()); }
|
||||||
int mkdirhier(const char *pathname, mode_t mode = 0755);
|
//int mkdirhier(const char *pathname, mode_t mode = 0755);
|
||||||
inline int mkdirhier(std::string path, mode_t mode = 0755) { return mkdirhier(path.c_str(), mode); }
|
//inline int mkdirhier(std::string path, mode_t mode = 0755) { return mkdirhier(path.c_str(), mode); }
|
||||||
off_t file_size(const char *filename);
|
off_t file_size(const char *filename);
|
||||||
bool file_exists(const char *filename);
|
bool file_exists(const char *filename);
|
||||||
void wakeup_hdd(const char *hdd_dir);
|
void wakeup_hdd(const char *hdd_dir);
|
||||||
@@ -88,7 +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);
|
||||||
bool createDir(const char *Dir, mode_t mode);
|
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);}
|
||||||
bool removeDir(const char *Dir);
|
bool removeDir(const char *Dir);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user