From f2611717d8fa1dc3b2c8e986f85287100f2daa2c Mon Sep 17 00:00:00 2001 From: eric Date: Sat, 29 Aug 2026 10:43:30 +0800 Subject: [PATCH 1/7] Update FileUtil.cpp --- codes/project/src/FileUtil.cpp | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/codes/project/src/FileUtil.cpp b/codes/project/src/FileUtil.cpp index f34add3ca..efe4a59eb 100644 --- a/codes/project/src/FileUtil.cpp +++ b/codes/project/src/FileUtil.cpp @@ -39,18 +39,25 @@ License #endif #include +#include BeginNameSpace( ONEFLOW ) -bool DirExist( const std::string & dirName ) -{ -#ifdef _WINDOWS - bool flag = ( _access( dirName.c_str(), 0 ) == 0 ); - return flag; -#else - bool flag = ( access( dirName.c_str(), 0 ) == 0 ); - return flag; -#endif +//bool DirExist( const std::string & dirName ) +//{ +//#ifdef _WINDOWS +// bool flag = ( _access( dirName.c_str(), 0 ) == 0 ); +// return flag; +//#else +// bool flag = ( access( dirName.c_str(), 0 ) == 0 ); +// return flag; +//#endif +//} + + +bool DirExist(const std::string& dirName) { + std::error_code ec; + return std::filesystem::is_directory(dirName, ec) && !ec; } void MakeDir( const std::string & dirName ) From 55bc1159c0ff2df2b50411cf72883cc46bfc3f74 Mon Sep 17 00:00:00 2001 From: eric Date: Sat, 29 Aug 2026 10:56:11 +0800 Subject: [PATCH 2/7] update linux.yml --- .github/workflows/linux.yml | 19 +++++++++++-------- codes/project/src/FileUtil.cpp | 12 ------------ 2 files changed, 11 insertions(+), 20 deletions(-) diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index a93c74c80..a7cfb0ab3 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -14,7 +14,10 @@ on: workflow_dispatch: permissions: - contents: read + contents: read + +env: + GCC_VERSION: 12 # 这里修改 10 /11 /12 /13 切换编译器版本 # A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: @@ -23,12 +26,12 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v5 - - name: Install GCC-10 + - name: Install GCC ${{ env.GCC_VERSION }} run: | sudo apt-get update - sudo apt install gcc-10 g++-10 -y - gcc --version - g++ --version + sudo apt install gcc-${{ env.GCC_VERSION }} g++-${{ env.GCC_VERSION }} -y + gcc-${{ env.GCC_VERSION }} --version + g++-${{ env.GCC_VERSION }} --version ls /usr/bin/gcc* shell: bash - name: Install Third party library @@ -41,9 +44,9 @@ jobs: sudo apt-get install libhdf5-dev libcgns-dev libmetis-dev libmpich-dev -y shell: bash - name: CMake Build and Install - #env: - # CC: gcc-10 - # CXX: g++-10 + env: + CC: gcc-${{ env.GCC_VERSION }} + CXX: g++-${{ env.GCC_VERSION }} run: | cd ${{ github.workspace }} ls diff --git a/codes/project/src/FileUtil.cpp b/codes/project/src/FileUtil.cpp index efe4a59eb..104f0c3dd 100644 --- a/codes/project/src/FileUtil.cpp +++ b/codes/project/src/FileUtil.cpp @@ -43,18 +43,6 @@ License BeginNameSpace( ONEFLOW ) -//bool DirExist( const std::string & dirName ) -//{ -//#ifdef _WINDOWS -// bool flag = ( _access( dirName.c_str(), 0 ) == 0 ); -// return flag; -//#else -// bool flag = ( access( dirName.c_str(), 0 ) == 0 ); -// return flag; -//#endif -//} - - bool DirExist(const std::string& dirName) { std::error_code ec; return std::filesystem::is_directory(dirName, ec) && !ec; From a4bad5701404cbfc425dd8a598601dafd83f1472 Mon Sep 17 00:00:00 2001 From: eric Date: Sat, 29 Aug 2026 11:27:40 +0800 Subject: [PATCH 3/7] modify bool MakeDir(const std::string& dirName) --- codes/project/include/FileUtil.h | 3 +- codes/project/src/FileUtil.cpp | 60 +++++++++++++++++++++++--------- 2 files changed, 46 insertions(+), 17 deletions(-) diff --git a/codes/project/include/FileUtil.h b/codes/project/include/FileUtil.h index 37b385c47..57824227d 100644 --- a/codes/project/include/FileUtil.h +++ b/codes/project/include/FileUtil.h @@ -32,7 +32,8 @@ License BeginNameSpace( ONEFLOW ) bool DirExist( const std::string & dirName ); -void MakeDir( const std::string & dirName ); +//void MakeDir( const std::string & dirName ); +bool MakeDir( const std::string & dirName ); std::string HX_GetExePath(); std::string HX_GetCurrentDir(); diff --git a/codes/project/src/FileUtil.cpp b/codes/project/src/FileUtil.cpp index 104f0c3dd..62754f06b 100644 --- a/codes/project/src/FileUtil.cpp +++ b/codes/project/src/FileUtil.cpp @@ -43,27 +43,55 @@ License BeginNameSpace( ONEFLOW ) -bool DirExist(const std::string& dirName) { +bool DirExist(const std::string& dirName) +{ std::error_code ec; return std::filesystem::is_directory(dirName, ec) && !ec; } -void MakeDir( const std::string & dirName ) +//void MakeDir( const std::string & dirName ) +//{ +// int flag; +//#ifdef _WINDOWS +// flag = _mkdir( dirName.c_str() ); +//#else +// #ifdef WIN_GNU +// flag = _mkdir( dirName.c_str() ); +// #else +// flag = mkdir( dirName.c_str(), S_IRWXU ); +// #endif +//#endif +// +// if ( flag == 0 ) +// { +// std::cout << dirName << " directory has been created successfully !\n"; +// } +//} + +bool MakeDir(const std::string& dirName) { - int flag; -#ifdef _WINDOWS - flag = _mkdir( dirName.c_str() ); -#else - #ifdef WIN_GNU - flag = _mkdir( dirName.c_str() ); - #else - flag = mkdir( dirName.c_str(), S_IRWXU ); - #endif -#endif - - if ( flag == 0 ) - { - std::cout << dirName << " directory has been created successfully !\n"; + try { + if (std::filesystem::exists(dirName)) { + if (std::filesystem::is_directory(dirName)) { + std::cout << "Directory already exists: " << dirName << std::endl; + return true; + } else { + std::cerr << "Path exists but is not a directory: " << dirName << std::endl; + return false; + } + } + + // Ŀ¼ĬȨޣֵ֧ݹ飩 + if (std::filesystem::create_directories(dirName)) { + std::cout << "Directory created successfully: " << dirName << std::endl; + return true; + } else { + std::cerr << "Failed to create directory: " << dirName << std::endl; + return false; + } + } catch (const std::filesystem::filesystem_error& e) { + std::cerr << "Filesystem error: " << e.what() << std::endl; + return false; } } From 9dfcebd94c14cd5a3e3ac1b9a3a6715ad6964303 Mon Sep 17 00:00:00 2001 From: eric Date: Sun, 30 Aug 2026 00:31:19 +0800 Subject: [PATCH 4/7] Update FileUtil.cpp --- codes/project/src/FileUtil.cpp | 44 +++++++++++++--------------------- 1 file changed, 17 insertions(+), 27 deletions(-) diff --git a/codes/project/src/FileUtil.cpp b/codes/project/src/FileUtil.cpp index 62754f06b..df85c6e8d 100644 --- a/codes/project/src/FileUtil.cpp +++ b/codes/project/src/FileUtil.cpp @@ -49,25 +49,6 @@ bool DirExist(const std::string& dirName) return std::filesystem::is_directory(dirName, ec) && !ec; } -//void MakeDir( const std::string & dirName ) -//{ -// int flag; -//#ifdef _WINDOWS -// flag = _mkdir( dirName.c_str() ); -//#else -// #ifdef WIN_GNU -// flag = _mkdir( dirName.c_str() ); -// #else -// flag = mkdir( dirName.c_str(), S_IRWXU ); -// #endif -//#endif -// -// if ( flag == 0 ) -// { -// std::cout << dirName << " directory has been created successfully !\n"; -// } -//} - bool MakeDir(const std::string& dirName) { try { @@ -108,16 +89,25 @@ std::string HX_GetExePath() } +//std::string HX_GetCurrentDir() +//{ +//#ifdef _WINDOWS +// char * cwd = _getcwd( 0, 0 ); +//#else +// char * cwd = getcwd( 0, 0 ); +//#endif +// std::string working_dir( cwd ) ; +// std::free( cwd ) ; +// return working_dir ; +//} + std::string HX_GetCurrentDir() { -#ifdef _WINDOWS - char * cwd = _getcwd( 0, 0 ); -#else - char * cwd = getcwd( 0, 0 ); -#endif - std::string working_dir( cwd ) ; - std::free( cwd ) ; - return working_dir ; + try { + return std::filesystem::current_path().string(); + } catch (const std::filesystem::filesystem_error&) { + return {}; // or rethrow / log the error + } } bool EndWithSlash( const std::string & fileName ) From ac540bf35b583746627df53cefc7a27b392eb743 Mon Sep 17 00:00:00 2001 From: eric Date: Sun, 30 Aug 2026 01:10:36 +0800 Subject: [PATCH 5/7] std::filesystem::path HX_GetExeDirectory() --- codes/project/include/FileUtil.h | 5 +++-- codes/project/src/FileUtil.cpp | 38 +++++++++++++++++++++++++++----- codes/project/src/Prj.cpp | 2 +- 3 files changed, 36 insertions(+), 9 deletions(-) diff --git a/codes/project/include/FileUtil.h b/codes/project/include/FileUtil.h index 57824227d..90587b629 100644 --- a/codes/project/include/FileUtil.h +++ b/codes/project/include/FileUtil.h @@ -28,14 +28,15 @@ License #include #include #include +#include BeginNameSpace( ONEFLOW ) bool DirExist( const std::string & dirName ); -//void MakeDir( const std::string & dirName ); bool MakeDir( const std::string & dirName ); -std::string HX_GetExePath(); +//std::string HX_GetExeDirectory(); +std::filesystem::path HX_GetExeDirectory(); std::string HX_GetCurrentDir(); bool EndWithSlash( const std::string & fileName ); diff --git a/codes/project/src/FileUtil.cpp b/codes/project/src/FileUtil.cpp index df85c6e8d..09434e905 100644 --- a/codes/project/src/FileUtil.cpp +++ b/codes/project/src/FileUtil.cpp @@ -76,16 +76,42 @@ bool MakeDir(const std::string& dirName) } } -std::string HX_GetExePath() +//std::string HX_GetExeDirectory() +//{ +// char buffer[ FILENAME_MAX ] = { 0 }; +//#ifdef _WIN32 +// GetModuleFileName( NULL, buffer, FILENAME_MAX ); +//#else +// std::size_t count = readlink( "/proc/self/exe", buffer, FILENAME_MAX ); +//#endif +// std::string::size_type pos = std::string( buffer ).find_last_of( "\\/" ); +// return std::string( buffer ).substr( 0, pos); +//} + +std::filesystem::path HX_GetExeDirectory() { - char buffer[ FILENAME_MAX ] = { 0 }; #ifdef _WIN32 - GetModuleFileName( NULL, buffer, FILENAME_MAX ); + std::wstring wbuf(MAX_PATH, L'\0'); + DWORD len = 0; + while (true) { + len = GetModuleFileNameW(nullptr, wbuf.data(), static_cast(wbuf.size())); + if (len == 0) return {}; + if (len < wbuf.size()) break; + wbuf.resize(wbuf.size() * 2); + } + return std::filesystem::path(wbuf.substr(0, len)).parent_path(); #else - std::size_t count = readlink( "/proc/self/exe", buffer, FILENAME_MAX ); + std::vector buf(PATH_MAX); + ssize_t count = -1; + while (true) { + count = readlink("/proc/self/exe", buf.data(), buf.size()); + if (count < 0) return {}; + if (static_cast(count) < buf.size()) break; + buf.resize(buf.size() * 2); + } + buf[count] = '\0'; + return std::filesystem::path(std::string(buf.data(), count)).parent_path(); #endif - std::string::size_type pos = std::string( buffer ).find_last_of( "\\/" ); - return std::string( buffer ).substr( 0, pos); } diff --git a/codes/project/src/Prj.cpp b/codes/project/src/Prj.cpp index 09495a1a3..aacab215b 100644 --- a/codes/project/src/Prj.cpp +++ b/codes/project/src/Prj.cpp @@ -60,7 +60,7 @@ void Prj::ProcessCmdLineArgs( std::vector &args ) void Prj::Init() { - Prj::execute_dir = HX_GetExePath(); + Prj::execute_dir = HX_GetExeDirectory().string(); Prj::current_dir = HX_GetCurrentDir(); std::cout << " Prj::execute_dir = " << Prj::execute_dir << "\n"; From 6f42294a1689350b4555e13d5cf0f3b2380e30e6 Mon Sep 17 00:00:00 2001 From: eric Date: Sun, 30 Aug 2026 01:23:29 +0800 Subject: [PATCH 6/7] Update FileUtil.cpp --- codes/project/src/FileUtil.cpp | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/codes/project/src/FileUtil.cpp b/codes/project/src/FileUtil.cpp index 09434e905..fc64e3f1f 100644 --- a/codes/project/src/FileUtil.cpp +++ b/codes/project/src/FileUtil.cpp @@ -38,6 +38,8 @@ License #endif #endif +#include +#include #include #include @@ -115,18 +117,6 @@ std::filesystem::path HX_GetExeDirectory() } -//std::string HX_GetCurrentDir() -//{ -//#ifdef _WINDOWS -// char * cwd = _getcwd( 0, 0 ); -//#else -// char * cwd = getcwd( 0, 0 ); -//#endif -// std::string working_dir( cwd ) ; -// std::free( cwd ) ; -// return working_dir ; -//} - std::string HX_GetCurrentDir() { try { From dec3a07e798bd58b4497c88a9873c1bd0037ae2f Mon Sep 17 00:00:00 2001 From: eric Date: Sun, 30 Aug 2026 01:39:53 +0800 Subject: [PATCH 7/7] copyright = '2017~2024, eric'->copyright = '2017-2026, eric' --- codes/project/src/FileUtil.cpp | 12 ------------ doc/source/conf.py | 2 +- 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/codes/project/src/FileUtil.cpp b/codes/project/src/FileUtil.cpp index fc64e3f1f..7f07eac42 100644 --- a/codes/project/src/FileUtil.cpp +++ b/codes/project/src/FileUtil.cpp @@ -78,18 +78,6 @@ bool MakeDir(const std::string& dirName) } } -//std::string HX_GetExeDirectory() -//{ -// char buffer[ FILENAME_MAX ] = { 0 }; -//#ifdef _WIN32 -// GetModuleFileName( NULL, buffer, FILENAME_MAX ); -//#else -// std::size_t count = readlink( "/proc/self/exe", buffer, FILENAME_MAX ); -//#endif -// std::string::size_type pos = std::string( buffer ).find_last_of( "\\/" ); -// return std::string( buffer ).substr( 0, pos); -//} - std::filesystem::path HX_GetExeDirectory() { #ifdef _WIN32 diff --git a/doc/source/conf.py b/doc/source/conf.py index 7acd13cac..a3285a565 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -7,7 +7,7 @@ # https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information project = 'Scientific Computing' -copyright = '2017~2024, eric' +copyright = '2017-2026, eric' author = 'eric' release = '1.0'