Skip to content

Refactor create_file for posix#199

Merged
bugdea1er merged 4 commits into
mainfrom
posix-create-file
Apr 19, 2025
Merged

Refactor create_file for posix#199
bugdea1er merged 4 commits into
mainfrom
posix-create-file

Conversation

@bugdea1er
Copy link
Copy Markdown
Owner

@bugdea1er bugdea1er commented Apr 19, 2025

Remove the create_file(std::error_code&) overload

@bugdea1er bugdea1er requested a review from Copilot April 19, 2025 12:40
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the create_file function for POSIX environments by removing the error-code–returning overload and inlining temporary-file creation logic in the default overload. Key changes include:

  • Removal of the create_file(std::error_code&) overload.
  • Inlining the logic to first try O_TMPFILE and fallback to mkstemp, storing errno before unlinking.
  • Throwing a fs::filesystem_error on failure instead of returning an error code.
Comments suppressed due to low confidence (1)

src/create.cpp:202

  • [nitpick] Consider renaming 'create_error' to something like 'mkstemp_errno' to better convey that it captures the errno value post mkstemp.
int create_error = errno;

@bugdea1er bugdea1er requested a review from Copilot April 19, 2025 13:12
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the temporary file creation logic on POSIX systems by removing the error_code–based overload and introducing exception–based error handling.

  • Removed the legacy create_file(std::error_code&) overload
  • Updated the create_file() function to use exception throwing on file creation failure
  • Simplified and centralized the temporary file creation flow using O_TMPFILE and mkstemp
Comments suppressed due to low confidence (2)

src/create.cpp:154

  • [nitpick] The removal of the error_code-based overload changes the error handling behavior. Please verify that all call sites have been updated to handle exceptions instead of error codes.
#else

src/create.cpp:202

  • [nitpick] Since this branch now throws an exception on mkstemp failure, make sure that the exception handling is consistent with the rest of the project and that callers are prepared for this behavior shift.
if (handle == -1) {

@bugdea1er bugdea1er marked this pull request as ready for review April 19, 2025 15:05
@bugdea1er bugdea1er merged commit 9ae7319 into main Apr 19, 2025
16 checks passed
@bugdea1er bugdea1er deleted the posix-create-file branch April 19, 2025 15:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants