Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle abspath for output folder creation #314

Merged

Conversation

drbergman
Copy link
Collaborator

@drbergman drbergman commented Oct 23, 2024

any path starting with the path separator (indicating an absolute path) will cause an error with the current implementation even if the path already exists. This is because it attempts to create a directory with the empty string. This handles checking for that case. It splits on OS to check the path separator. For windows, it checks for the abspath starting with the drive. If we can upgrade to c++17, we could take advantage of std::filesystem to greatly simplify this. something like

// Function that we could use if we used c++17
// THIS IS NOT WHAT IS IMPLEMENTED IN THIS PR
bool create_directories(const std::string &path)
{
    std::error_code ec;
    bool success = std::filesystem::create_directories(path, ec);
    if (!success && ec) {
        // Handle error or log it, if necessary
        return false;
    }
    return true;
}

@rheiland
Copy link
Collaborator

On my Windows machine, using:

PS C:\Users\randy\dev\PhysiCell-fix-create-output-from-abspath\PhysiCell-fix-create-output-from-abspath> g++ --version
g++.exe (Rev6, Built by MSYS2 project) 13.1.0

I got an error if my absolute path started with a "/". However, if I prefixed it with the drive: "c:/" then it worked, e.g.:

<folder>c:/Users/randy/dev/PhysiCell-fix-create-output-from-abspath/PhysiCell-fix-create-output-from-abspath/out2</folder>

@drbergman drbergman requested a review from rheiland October 24, 2024 13:01
@drbergman drbergman added the bug label Oct 24, 2024
@MathCancer MathCancer merged commit 631ce30 into MathCancer:development Dec 12, 2024
208 of 209 checks passed
@drbergman drbergman deleted the fix-create-output-from-abspath branch December 12, 2024 21:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants