Avoid Error when debug dir didn't exist
@@ -18,6 +18,12 @@ limitations under the License.
#include <cstring>
#include <cstdio>
#include <ctime>
+{% if config.debug %}
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <errno.h>
+{% endif %}
#include "global.h"
#include "func/add.h"
#include "func/average_pool.h"
@@ -227,6 +233,21 @@ bool Network::init()
#pragma omp parallel
std::cout << std::flush;
+ {% if config.debug -%}
+ const auto debug_path = "debug";
+ struct stat debug_dir_stat;
+ auto ret = stat(debug_path, &debug_dir_stat);
+ if (ret == -1 && errno == ENOENT) {
+ mkdir(debug_path, 0755);
+ std::cerr << "Info: debug directory is created" << std::endl;
+ } else if (S_ISDIR(debug_dir_stat.st_mode)) {
+ std::cerr << "Warning: debug directory will be overwritten" << std::endl;
+ } else {
+ std::cerr << "Error: '" << debug_path << "' is not a directory" << std::endl;
+ exit(EXIT_FAILURE);
+ }
+ {% endif -%}
+
return true;
}
