Merge pull request #1071 from daym/samefile
Prevent hardLinkFile from unlinking a target just to then turn around…
commit e5e2f9141e9f40d9a01f76dff55f4c5ef89361b2
2 parents 902ef9c + e9adbd6
@Martin Nowak Martin Nowak authored on 13 Feb 2017
GitHub committed on 13 Feb 2017
Showing 1 changed file
View
18
source/dub/internal/vibecompat/core/file.d
 
// guess whether 2 files are identical, ignores filename and content
private bool sameFile(Path a, Path b)
{
static assert(__traits(allMembers, FileInfo)[0] == "name");
return getFileInfo(a).tupleof[1 .. $] == getFileInfo(b).tupleof[1 .. $];
version (Posix) {
auto st_a = std.file.DirEntry(a.toNativeString).statBuf;
auto st_b = std.file.DirEntry(b.toNativeString).statBuf;
return st_a == st_b;
} else {
static assert(__traits(allMembers, FileInfo)[0] == "name");
return getFileInfo(a).tupleof[1 .. $] == getFileInfo(b).tupleof[1 .. $];
}
}
 
/**
Creates a hardlink.
{
if (existsFile(to)) {
enforce(overwrite, "Destination file already exists.");
if (auto fe = collectException!FileException(removeFile(to))) {
version (Windows) if (sameFile(from, to)) return;
if (sameFile(from, to)) return;
throw fe;
}
}