From 9583df3c4414994dc36411e8d9e0af3ac7253d80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Mon, 14 Jan 2019 00:32:27 +0100 Subject: [PATCH] Preserve times and attributes in copyFile. --- source/vibe/core/file.d | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/source/vibe/core/file.d b/source/vibe/core/file.d index 6530a1e..0ad3711 100644 --- a/source/vibe/core/file.d +++ b/source/vibe/core/file.d @@ -214,6 +214,17 @@ void moveFile(string from, string to, bool copy_fallback = false) */ void copyFile(NativePath from, NativePath to, bool overwrite = false) { + DirEntry info; + static if (__VERSION__ < 2078) { + () @trusted { + info = DirEntry(from.toString); + enforce(info.isFile, "The source path is not a file and cannot be copied."); + } (); + } else { + info = DirEntry(from.toString); + enforce(info.isFile, "The source path is not a file and cannot be copied."); + } + { auto src = openFile(from, FileMode.read); scope(exit) src.close(); @@ -223,7 +234,17 @@ void copyFile(NativePath from, NativePath to, bool overwrite = false) dst.write(src); } - // TODO: retain attributes and time stamps + // TODO: also retain creation time on windows + + static if (__VERSION__ < 2078) { + () @trusted { + setAttributes(to.toString, info.attributes); + setTimes(to.toString, info.timeLastAccessed, info.timeLastModified); + } (); + } else { + setAttributes(to.toString, info.attributes); + setTimes(to.toString, info.timeLastAccessed, info.timeLastModified); + } } /// ditto void copyFile(string from, string to)