D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 17241 - std.file.rename exceptions should include both 'from' and 'to' file paths
Summary: std.file.rename exceptions should include both 'from' and 'to' file paths
Status: RESOLVED WORKSFORME
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: x86_64 Linux
: P1 minor
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-03-03 01:31 UTC by Ali Cehreli
Modified: 2020-03-21 03:56 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Ali Cehreli 2017-03-03 01:31:43 UTC
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 basile-z 2017-12-21 01:03:21 UTC
It set to

            enforce(false,
                new FileException(
                    text("Attempting to rename file ", f, " to ", t)));


now.