@@ -7,6 +7,12 @@ static const int32_t kTmpLen = 1024;
77
88static char _tmpb[kTmpLen ];
99
10+ static const char * kLibDir = " /lib" ;
11+ static const char * kUsrDir = " /usr" ;
12+ static const char * kIncDir = " /inc" ;
13+ static const char * kConfDir = " /conf" ;
14+ static const char * kUtilDir = " /butl" ;
15+
1016FsCreator::FsCreator ()
1117{
1218}
@@ -36,10 +42,12 @@ bool FsCreator::PrepareDirectory(std::string drvname, std::string basepath, bool
3642 }
3743 else
3844 {
45+ std::string separator = basepath.at (basepath.size () - 1 ) == ' /' ? " " : " /" ;
46+
3947 for (int32_t dirnum = 0 ; dirnum < 1000 ; dirnum++)
4048 {
4149 snprintf (_tmpb, kTmpLen , " %03d" , dirnum);
42- work_dir_path = basepath + " / " + _tmpb;
50+ work_dir_path = basepath + separator + _tmpb;
4351
4452 if (stat (work_dir_path.c_str (), &info) != 0 )
4553 {
@@ -63,9 +71,44 @@ bool FsCreator::PrepareDirectory(std::string drvname, std::string basepath, bool
6371 }
6472 }
6573 }
74+
75+ FS.libdir = work_dir_path + kLibDir ;
76+
77+ if (std::filesystem::create_directory (FS.libdir ))
78+ {
79+ // ret = false;
80+ }
81+
82+ FS.usrdir = work_dir_path + kUsrDir ;
83+
84+ if (std::filesystem::create_directory (FS.usrdir ))
85+ {
86+ // ret = false;
87+ }
88+
89+ FS.incdir = work_dir_path + kIncDir ;
90+
91+ if (std::filesystem::create_directory (FS.incdir ))
92+ {
93+ // ret = false;
94+ }
95+
96+ FS.confdir = work_dir_path + kConfDir ;
97+
98+ if (std::filesystem::create_directory (FS.confdir ))
99+ {
100+ // ret = false;
101+ }
102+
103+ FS.utildir = work_dir_path + kUtilDir ;
104+
105+ if (std::filesystem::create_directory (FS.utildir ))
106+ {
107+ // ret = false;
108+ }
66109 }
67110
68- if (ret )
111+ if (true )
69112 {
70113 // directory valid and exists, set all the values
71114 FS.DrvName_orig = drvname;
@@ -74,11 +117,11 @@ bool FsCreator::PrepareDirectory(std::string drvname, std::string basepath, bool
74117
75118 FS.core_h .dir = work_dir_path;
76119 FS.core_h .fname = FS.drvname + " .h" ;
77- FS.core_h .fpath = work_dir_path + " /" + FS.core_h .fname ;
120+ FS.core_h .fpath = FS. libdir + " /" + FS.core_h .fname ;
78121
79122 FS.core_c .dir = work_dir_path;
80123 FS.core_c .fname = FS.drvname + " .c" ;
81- FS.core_c .fpath = work_dir_path + " /" + FS.core_c .fname ;
124+ FS.core_c .fpath = FS. libdir + " /" + FS.core_c .fname ;
82125
83126 FS.util_h .dir = work_dir_path;
84127 FS.util_h .fname = FS.drvname + " -binutil" + " .h" ;
@@ -90,11 +133,11 @@ bool FsCreator::PrepareDirectory(std::string drvname, std::string basepath, bool
90133
91134 FS.fmon_h .dir = work_dir_path;
92135 FS.fmon_h .fname = FS.drvname + " -fmon.h" ;
93- FS.fmon_h .fpath = work_dir_path + " /" + FS.fmon_h .fname ;
136+ FS.fmon_h .fpath = FS. libdir + " /" + FS.fmon_h .fname ;
94137
95138 FS.fmon_c .dir = work_dir_path;
96139 FS.fmon_c .fname = FS.drvname + " -fmon.c" ;
97- FS.fmon_c .fpath = work_dir_path + " /" + FS.fmon_c .fname ;
140+ FS.fmon_c .fpath = FS. usrdir + " /" + FS.fmon_c .fname ;
98141
99142 snprintf (_tmpb, kTmpLen , " %s_USE_BITS_SIGNAL" , FS.DRVNAME .c_str ());
100143 FS.usebits_def = _tmpb;
@@ -131,3 +174,42 @@ bool FsCreator::PrepareDirectory(std::string drvname, std::string basepath, bool
131174
132175 return ret;
133176}
177+
178+ std::string FsCreator::CreateSubDir (std::string basepath, std::string sub, bool rw)
179+ {
180+ std::string ret = basepath;
181+ struct stat info;
182+
183+ if (basepath.size () == 0 || sub.size () == 0 )
184+ {
185+ return " " ;
186+ }
187+
188+ if (basepath.at (basepath.size () - 1 ) != ' /' )
189+ {
190+ basepath.append (" /" );
191+ }
192+
193+ basepath.append (sub);
194+
195+ bool ok = true ;
196+
197+ if (stat (basepath.c_str (), &info) != 0 && rw)
198+ {
199+ // directory already exists and rewrite option is requested
200+ ok = std::filesystem::remove (basepath);
201+ }
202+
203+ if (!ok)
204+ {
205+ // error on removing directory
206+ return " " ;
207+ }
208+
209+ if (std::filesystem::create_directory (basepath) != 0 )
210+ {
211+ ret = " " ;
212+ }
213+
214+ return basepath;
215+ }
0 commit comments