Skip to content

Commit

Permalink
Merge pull request #994 from WebDrake/fix-posix-copy
Browse files Browse the repository at this point in the history
Remove POSIX special-casing from copyFile.
  • Loading branch information
s-ludwig authored Nov 13, 2016
2 parents defd678 + 4538594 commit c6b74d4
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions source/dub/internal/vibecompat/core/file.d
Original file line number Diff line number Diff line change
Expand Up @@ -112,20 +112,26 @@ void copyFile(Path from, Path to, bool overwrite = false)
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
Expand Down

0 comments on commit c6b74d4

Please sign in to comment.