diff --git a/source/dub/generators/build.d b/source/dub/generators/build.d index e7b057a..d07d5ba 100644 --- a/source/dub/generators/build.d +++ b/source/dub/generators/build.d @@ -306,7 +306,7 @@ logDiagnostic("Copying target from %s to %s", src.toNativeString(), buildsettings.targetPath); if (!existsFile(Path(buildsettings.targetPath))) mkdirRecurse(buildsettings.targetPath); - symlinkFile(src, Path(buildsettings.targetPath) ~ filename, true); + hardLinkFile(src, Path(buildsettings.targetPath) ~ filename, true); } private bool isUpToDate(Path target_path, BuildSettings buildsettings, BuildPlatform platform, in Package main_pack, in Package[] packages, in Path[] additional_dep_files) diff --git a/source/dub/internal/vibecompat/core/file.d b/source/dub/internal/vibecompat/core/file.d index 0e004dd..73fe3eb 100644 --- a/source/dub/internal/vibecompat/core/file.d +++ b/source/dub/internal/vibecompat/core/file.d @@ -135,29 +135,33 @@ copyFile(Path(from), Path(to)); } +version (Windows) extern(Windows) int CreateHardLinkW(in wchar* to, in wchar* from, void* attr=null); + /** - Creates a symlink. + Creates a hardlink. */ -version (Windows) - alias symlinkFile = copyFile; // TODO: symlinks on Windows -else version (Posix) +void hardLinkFile(Path from, Path to, bool overwrite = false) { - void symlinkFile(Path from, Path to, bool overwrite = false) - { - if (existsFile(to)) { - enforce(overwrite, "Destination file already exists."); - // remove file before copy to allow "overwriting" files that are in - // use on Linux - removeFile(to); - } - - .symlink(from.toNativeString(), to.toNativeString()); + if (existsFile(to)) { + enforce(overwrite, "Destination file already exists."); + removeFile(to); } -} -void symlinkFile(string from, string to) -{ - symlinkFile(Path(from), Path(to)); + version (Windows) + { + alias cstr = toUTFz!(const(wchar)*); + if (CreateHardLinkW(cstr(to.toNativeString), cstr(from.toNativeString))) + return; + } + else + { + import core.sys.posix.unistd : link; + alias cstr = toUTFz!(const(char)*); + if (!link(cstr(from.toNativeString), cstr(to.toNativeString))) + return; + } + // fallback to copy + copyFile(from, to, overwrite); } /**