According to this https://en.cppreference.com/w/cpp/filesystem/rename
filesystem::rename does not handle 2 cases.
Case 1: Renaming files which are hard-links of each other should be a no-op
Command-line test case
C:\Temp> echo "hello" > f1
C:\Temp> mklink /H f1 f2
C:\Temp>type c1.cpp
#include <filesystem>
int main() {
std::filesystem::rename("f1","f2");
}
C:\Temp>cl /EHsc /W4 /std:c++17 .\c1.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 19.23.28019.1 for x64
Copyright (C) Microsoft Corporation. All rights reserved.
c1.cpp
Microsoft (R) Incremental Linker Version 14.23.28019.1
Copyright (C) Microsoft Corporation. All rights reserved.
/out:c1.exe
c1.obj
C:\Temp>.\c1.exe
Expected behavior
C:\Temp> dir /B
f1
f2
Observed behavior
C:\Temp> dir /B
f2
Case 2: In case of renaming directories where the new path points to an empty directory, the operation should not fail
Command-line test case
C:\Temp> mkdir mydir
C:\Temp> echo "hello" > mydir\f1
C:\Temp> mkdir emptydir
C:\Temp>type c2.cpp
#include <filesystem>
int main() {
std::filesystem::rename("mydir","emptydir");
}
C:\Temp>cl /EHsc /W4 /std:c++17 .\c2.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 19.23.28019.1 for x64
Copyright (C) Microsoft Corporation. All rights reserved.
c2.cpp
Microsoft (R) Incremental Linker Version 14.23.28019.1
Copyright (C) Microsoft Corporation. All rights reserved.
/out:c2.exe
c2.obj
C:\Temp>.\c2.exe
Expected behavior
C:\Temp> dir /B /S
C:\Temp\emptydir
C:\Temp\emptydir\f1
Observed behavior
C:\Temp> dir /B /S
C:\Temp\emptydir
C:\Temp\mydir
C:\Temp\mydir\f1
STL version
https://github.com/microsoft/STL/commit/e745bad3b1d05b5b19ec652d68abb37865ffa454
According to this https://en.cppreference.com/w/cpp/filesystem/rename
filesystem::renamedoes not handle 2 cases.Case 1: Renaming files which are hard-links of each other should be a no-op
Command-line test case
Case 2: In case of renaming directories where the new path points to an empty directory, the operation should not fail
Command-line test case
STL version