`<filesystem>`: `rename` is not POSIX compliant
Open
Nobody has claimed this yet.
bug
filesystem
- Dominant language
- C++
- Stars
- 11.1k
- Forks
- 1.7k
- Avg merge
- 4d 15h
- Merged PRs (30d)
- 22
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the implementation and tests for std::filesystem::rename, using the two Windows command-line cases in this issue as reproductions. Verify the hard-link case remains unchanged and that renaming onto an empty directory produces the expected directory listing without an error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- operating-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100