Skip to content

Conversation

@vszakats
Copy link
Member

@vszakats vszakats commented Dec 20, 2025

Move existing Curl_rename() rename() wrapper from lib to
curlx/fopen, and make it a curlx macro/function. To allow using
the local worker function to fixup long filenames on Windows.

Then fix the Windows-specific rename implementation to support long
filenames. This operation may happen when using a cookie jar, HSTS cache
or alt-svc cache, via libcurl or the curl tool.

Before this patch, when passing a long filename to the above options,
a <random>.tmp file was left on the disk without renaming it to the
filename passed to curl. There was also 1 second delay for each
attempted rename operation.

Also:

  • checksrc: ban raw rename() and MoveFileEx*() functions.
  • Note: Curl_rename() returned 1 on failure before this patch, while
    curlx_rename() returns -1 after, to match POSIX rename().

Refs:
https://learn.microsoft.com/windows/win32/api/winbase/nf-winbase-movefileexa
https://learn.microsoft.com/windows/win32/fileio/maximum-file-path-limitation

Ref: #20040


  • rebase on windows: fix CreateFile() calls to support long filenames #20040.
  • add long filename support to curlx_win32_rename().
  • possibly address potentially broken build when UNICODE != _UNICODE.
    Though I believe such build makes little practical sense, let alone supporting it.
    setup-win32.h has protection against mixing them, so UNICODE == _UNICODE
    is guaranteed. Nice!

@vszakats vszakats marked this pull request as draft December 20, 2025 00:52
@testclutch

This comment was marked as outdated.

@vszakats vszakats changed the title curlx: move Curl_rename to curlx_rename [WIP] curlx: move Curl_rename to curlx_rename, add long filename support on Windows Dec 20, 2025
@vszakats vszakats marked this pull request as ready for review December 20, 2025 04:03
@vszakats vszakats changed the title curlx: move Curl_rename to curlx_rename, add long filename support on Windows curlx: add curlx_rename, with long filename support on Windows Dec 20, 2025
@vszakats vszakats requested a review from Copilot December 20, 2025 04:19
Copy link

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 file rename functionality by introducing curlx_rename with long filename support on Windows, replacing the previous Curl_rename() function. The key change is moving the implementation from standalone files to the existing curlx/fopen module and aligning the error return value with POSIX conventions (-1 for failure instead of 1).

  • Adds curlx_win32_rename() with Windows long path support using fix_excessive_path()
  • Updates three call sites (hsts.c, cookie.c, altsvc.c) to use the new curlx_rename API
  • Adds rename and MoveFileEx* functions to the banned functions list to enforce use of the wrapper

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
scripts/checksrc.pl Adds MoveFileEx, MoveFileExA, MoveFileExW, and rename to banned functions list
lib/rename.h Removes old header file containing Curl_rename declaration
lib/rename.c Removes old implementation file
lib/hsts.c Updates call from Curl_rename() to curlx_rename() and removes now-unnecessary include
lib/curlx/fopen.h Adds curlx_win32_rename declaration and defines curlx_rename macro
lib/curlx/fopen.c Implements curlx_win32_rename() with long filename support via fix_excessive_path()
lib/cookie.c Updates call from Curl_rename() to curlx_rename() and removes include
lib/altsvc.c Updates call from Curl_rename() to curlx_rename() and removes include
lib/Makefile.inc Removes rename.c and rename.h from build files list
docs/internals/CODE_STYLE.md Documents rename and MoveFileEx* as banned functions

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@vszakats vszakats changed the title curlx: add curlx_rename, with long filename support on Windows curlx: add curlx_rename(), with long filename support on Windows Dec 20, 2025
Copy link

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

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@vszakats vszakats added the Windows Windows-specific label Dec 20, 2025
@vszakats vszakats changed the title curlx: add curlx_rename(), with long filename support on Windows curlx: add curlx_rename(), fix long filename support on Windows Dec 20, 2025
@vszakats vszakats changed the title curlx: add curlx_rename(), fix long filename support on Windows curlx: add curlx_rename(), fix to support long filenames on Windows Dec 20, 2025
@vszakats vszakats closed this in 6d0ee7b Dec 20, 2025
@vszakats vszakats deleted the wmove branch December 20, 2025 15:03
@jay
Copy link
Member

jay commented Dec 20, 2025

Yes when UNICODE is defined we expect _UNICODE and vice versa that's why there's a compile-time sanity check in setup-win32

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Windows Windows-specific

Development

Successfully merging this pull request may close these issues.

3 participants