summaryrefslogtreecommitdiffstats
path: root/Source/cmFileCommand.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2022-11-17 18:27:21 (GMT)
committerBrad King <brad.king@kitware.com>2022-11-17 20:05:07 (GMT)
commitefa9eec0402adacc7ac8b0dc17660a8bd968b06a (patch)
tree4faf3121039e17ea3d951912b2aede27ef939f1e /Source/cmFileCommand.cxx
parentfa518188d8aeffa176109bc960173b06fa1e135e (diff)
downloadCMake-efa9eec0402adacc7ac8b0dc17660a8bd968b06a.zip
CMake-efa9eec0402adacc7ac8b0dc17660a8bd968b06a.tar.gz
CMake-efa9eec0402adacc7ac8b0dc17660a8bd968b06a.tar.bz2
file(COPY_FILE): Add option to retry on Windows if input access fails
On Windows, a file may be inaccessible for a short time after it is created. This occurs for various reasons, including indexing, antivirus tools, and NTFS's asynchronous semantics. Add an `INPUT_MAY_BE_RECENT` option to tell CMake that the input file may have been recently created so that we can retry a few times to read it.
Diffstat (limited to 'Source/cmFileCommand.cxx')
-rw-r--r--Source/cmFileCommand.cxx8
1 files changed, 7 insertions, 1 deletions
diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx
index 85f528d..cdd0408 100644
--- a/Source/cmFileCommand.cxx
+++ b/Source/cmFileCommand.cxx
@@ -1408,12 +1408,14 @@ bool HandleCopyFile(std::vector<std::string> const& args,
struct Arguments
{
+ bool InputMayBeRecent = false;
bool OnlyIfDifferent = false;
std::string Result;
};
static auto const parser =
cmArgumentParser<Arguments>{}
+ .Bind("INPUT_MAY_BE_RECENT"_s, &Arguments::InputMayBeRecent)
.Bind("ONLY_IF_DIFFERENT"_s, &Arguments::OnlyIfDifferent)
.Bind("RESULT"_s, &Arguments::Result);
@@ -1456,9 +1458,13 @@ bool HandleCopyFile(std::vector<std::string> const& args,
} else {
when = cmSystemTools::CopyWhen::Always;
}
+ cmSystemTools::CopyInputRecent const inputRecent = arguments.InputMayBeRecent
+ ? cmSystemTools::CopyInputRecent::Yes
+ : cmSystemTools::CopyInputRecent::No;
std::string err;
- if (cmSystemTools::CopySingleFile(oldname, newname, when, &err) ==
+ if (cmSystemTools::CopySingleFile(oldname, newname, when, inputRecent,
+ &err) ==
cmSystemTools::CopyResult::Success) {
if (!arguments.Result.empty()) {
status.GetMakefile().AddDefinition(arguments.Result, "0");