diff --git a/source/dub/internal/vibecompat/core/file.d b/source/dub/internal/vibecompat/core/file.d index 1414329..b452602 100644 --- a/source/dub/internal/vibecompat/core/file.d +++ b/source/dub/internal/vibecompat/core/file.d @@ -115,7 +115,22 @@ // 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); + } } /// ditto void copyFile(string from, string to)