Remove POSIX special-casing from copyFile
Since `std.file.copy` provides a means to preserve attributes of a file
as of DMD 2.067.0 or later, it is preferable to use this option rather
than having a custom-written solution.  `version (Posix)` special-casing
is therefore used only where the DMD version does not support it.

Note that where the `version (Posix)` code uses a `chown` call followed
by a `chmod` call, `std.file.copy` only uses a `chmod`.  This is not
expected to cause any issues but should be borne in mind as a possible
breaking change for some use-cases.

Fixes https://github.com/dlang/dub/issues/992.
1 parent 803672c commit 4538594db148ae0cd0f099caca73bac6c7ebb6be
@Joseph Rushton Wakeling Joseph Rushton Wakeling authored on 13 Nov 2016
Showing 1 changed file
View
40
source/dub/internal/vibecompat/core/file.d
// use on Linux
removeFile(to);
}
 
.copy(from.toNativeString(), to.toNativeString());
 
// try to preserve ownership/permissions in Posix
version (Posix) {
import core.sys.posix.sys.stat;
import core.sys.posix.unistd;
import std.utf;
auto cspath = toUTFz!(const(char)*)(from.toNativeString());
auto cdpath = toUTFz!(const(char)*)(to.toNativeString());
stat_t st;
enforce(stat(cspath, &st) == 0, "Failed to get attributes of source file.");
if (chown(cdpath, st.st_uid, st.st_gid) != 0)
st.st_mode &= ~(S_ISUID | S_ISGID);
chmod(cdpath, st.st_mode);
static if (is(PreserveAttributes))
{
.copy(from.toNativeString(), to.toNativeString(), PreserveAttributes.yes);
}
else
{
.copy(from.toNativeString(), to.toNativeString());
// try to preserve ownership/permissions in Posix
version (Posix) {
import core.sys.posix.sys.stat;
import core.sys.posix.unistd;
import std.utf;
auto cspath = toUTFz!(const(char)*)(from.toNativeString());
auto cdpath = toUTFz!(const(char)*)(to.toNativeString());
stat_t st;
enforce(stat(cspath, &st) == 0, "Failed to get attributes of source file.");
if (chown(cdpath, st.st_uid, st.st_gid) != 0)
st.st_mode &= ~(S_ISUID | S_ISGID);
chmod(cdpath, st.st_mode);
}
}
}
/// ditto
void copyFile(string from, string to)