Skip to content

Commit

Permalink
Replace cleanup script and Win32-specific function with `std::files…
Browse files Browse the repository at this point in the history
…ystem` (#3292)

* Replace `cleanup` and Win32 script with std::filesystem

* Fixups

* Remove from cmake

* Update src/oc/hoc.cpp

Co-authored-by: Nicolas Cornu <[email protected]>

* Update src/oc/hoc.cpp

Co-authored-by: Nicolas Cornu <[email protected]>

* Put back Windows-specific part of cleanup

* Use `noexcept` version of `fs::remove`

* Declare the Windows function as `extern`

---------

Co-authored-by: Nicolas Cornu <[email protected]>
  • Loading branch information
JCGoran and Nicolas Cornu authored Dec 16, 2024
1 parent 6ab042f commit ad740c7
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 35 deletions.
2 changes: 0 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -916,8 +916,6 @@ install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/share/demo DESTINATION ${NRN_INSTA
install(FILES ${PROJECT_BINARY_DIR}/share/nrn/lib/nrnunits.lib
${PROJECT_BINARY_DIR}/share/nrn/lib/nrn.defaults
DESTINATION ${NRN_INSTALL_SHARE_DIR}/lib)
install(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/share/lib/cleanup
DESTINATION ${NRN_INSTALL_SHARE_DIR}/lib)

# Copy NEURON headers that will be included in the installation into the build directory.
set(headers_in_build_dir)
Expand Down
8 changes: 0 additions & 8 deletions share/lib/cleanup

This file was deleted.

21 changes: 9 additions & 12 deletions src/oc/hoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include <cfenv>
#include <condition_variable>
#include <filesystem>
#include <iostream>
#include <mutex>
#include <thread>
Expand Down Expand Up @@ -168,9 +169,7 @@ static int c = '\n'; /* global for use by warning() */
void set_intset() {
hoc_intset++;
}
#endif
#ifdef WIN32
extern void hoc_win32_cleanup();
extern void ivoc_win32_cleanup();
#endif

static int follow(int expect, int ifyes, int ifno); /* look ahead for >=, etc. */
Expand Down Expand Up @@ -960,16 +959,14 @@ void hoc_final_exit(void) {
rl_deprep_terminal();
#endif
ivoc_cleanup();
#ifdef WIN32
hoc_win32_cleanup();
#else
std::string cmd{neuron_home};
cmd += "/lib/cleanup ";
cmd += std::to_string(hoc_pid());
if (system(cmd.c_str())) { // fix warning: ignoring return value
return;
}
#if defined(WIN32) && HAVE_IV
ivoc_win32_cleanup();
#endif
auto tmp_dir = std::getenv("TEMP");
auto path = std::filesystem::path(tmp_dir ? std::string(tmp_dir) : "/tmp") /
fmt::format("oc{}.hl", hoc_pid());
std::error_code ec;
std::filesystem::remove(path, ec);
}

void hoc_quit(void) {
Expand Down
13 changes: 0 additions & 13 deletions src/oc/mswinprt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,19 +121,6 @@ char* hoc_back2forward(char* s) {
void ivoc_win32_cleanup();
#endif

void hoc_win32_cleanup() {
char buf[256];
char* path;
#if HAVE_IV
ivoc_win32_cleanup();
#endif
path = getenv("TEMP");
if (path) {
Sprintf(buf, "%s/oc%d.hl", path, getpid());
unlink(buf);
// DebugMessage("unlinked %s\n", buf);
}
}

void hoc_win_exec(void) {
int i;
Expand Down

0 comments on commit ad740c7

Please sign in to comment.