diff options
author | Brad King <brad.king@kitware.com> | 2021-03-04 13:13:16 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2021-03-04 13:49:48 (GMT) |
commit | 9bf40d8027ec9fb91ad995919f6db673c15558dc (patch) | |
tree | 2bac35f6c7d1be1e0788724ca86d1a3d9e5c43e2 /Source/cmFileCommand.cxx | |
parent | 3600c6cd8c09e501faa06be5f98465e994d51569 (diff) | |
download | CMake-9bf40d8027ec9fb91ad995919f6db673c15558dc.zip CMake-9bf40d8027ec9fb91ad995919f6db673c15558dc.tar.gz CMake-9bf40d8027ec9fb91ad995919f6db673c15558dc.tar.bz2 |
file(RENAME): Add option to not replace existing path
Add a `NO_REPLACE` option that prevents overwriting `<newname>`
if it exists.
Diffstat (limited to 'Source/cmFileCommand.cxx')
-rw-r--r-- | Source/cmFileCommand.cxx | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx index ab954f2..065b845 100644 --- a/Source/cmFileCommand.cxx +++ b/Source/cmFileCommand.cxx @@ -1333,11 +1333,13 @@ bool HandleRename(std::vector<std::string> const& args, struct Arguments { + bool NoReplace = false; std::string Result; }; - static auto const parser = - cmArgumentParser<Arguments>{}.Bind("RESULT"_s, &Arguments::Result); + static auto const parser = cmArgumentParser<Arguments>{} + .Bind("NO_REPLACE"_s, &Arguments::NoReplace) + .Bind("RESULT"_s, &Arguments::Result); std::vector<std::string> unconsumedArgs; Arguments const arguments = @@ -1349,13 +1351,22 @@ bool HandleRename(std::vector<std::string> const& args, std::string err; switch (cmSystemTools::RenameFile(oldname, newname, - cmSystemTools::Replace::Yes, &err)) { + arguments.NoReplace + ? cmSystemTools::Replace::No + : cmSystemTools::Replace::Yes, + &err)) { case cmSystemTools::RenameResult::Success: if (!arguments.Result.empty()) { status.GetMakefile().AddDefinition(arguments.Result, "0"); } return true; case cmSystemTools::RenameResult::NoReplace: + if (!arguments.Result.empty()) { + err = "NO_REPLACE"; + } else { + err = "path not replaced"; + } + CM_FALLTHROUGH; case cmSystemTools::RenameResult::Failure: if (!arguments.Result.empty()) { status.GetMakefile().AddDefinition(arguments.Result, err); |