Bug 17241 – std.file.rename exceptions should include both 'from' and 'to' file paths
Status
RESOLVED
Resolution
WORKSFORME
Severity
minor
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2017-03-03T01:31:43Z
Last change time
2020-03-21T03:56:38Z
Assigned to
No Owner
Creator
Ali Cehreli
Comments
Comment #0 by acehreli — 2017-03-03T01:31:43Z
Currently, the exception message makes sense only if the problem is with the 'to' file path.
1) BAD CASE:
import std.file;
void main() {
rename("some_non_existing_file.txt", "bar.txt");
}
Unfortunately, the exception includes the target file name:
std.file.FileException@std/file.d(681): bar.txt: No such file or directory
[...]
DISCUSSION: The fix seems to be trivial by replacing the last argument with fromz below:
phobos/std/file.d:681:
cenforce(core.stdc.stdio.rename(fromz, toz) == 0, t, toz);
However, it's not that simple because in some cases it's toz that needs to be reported.
2) GOOD CASE:
import std.file;
void main() {
// Assuming that foo.txt exists:
rename("foo.txt", "some/non/existing/path/bar.txt");
}
std.file.FileException@std/file.d(681): some/non/existing/path/bar.txt: No such file or directory
[...]
So, it makes sense to include both paths.
Comment #1 by b2.temp — 2017-12-21T01:03:21Z
It set to
enforce(false,
new FileException(
text("Attempting to rename file ", f, " to ", t)));
now.