diff options
author | Wouter Klouwen <wouter.klouwen@youview.com> | 2018-11-20 10:17:33 (GMT) |
---|---|---|
committer | Wouter Klouwen <wouter.klouwen@youview.com> | 2018-11-27 08:50:36 (GMT) |
commit | 12b471e828e4462cce4354c87bb4fe18aeb600e3 (patch) | |
tree | ac94c73bfff84d0f6af70104ec4ab686e81a27b3 /Source/cmFileCommand.cxx | |
parent | d851a8b457251a577f10055d9fb277b75a82da6c (diff) | |
download | CMake-12b471e828e4462cce4354c87bb4fe18aeb600e3.zip CMake-12b471e828e4462cce4354c87bb4fe18aeb600e3.tar.gz CMake-12b471e828e4462cce4354c87bb4fe18aeb600e3.tar.bz2 |
file: add SIZE option
This commit adds the SIZE option to file(). It returns the file size of
the given path if it exists and produces an error if not.
Diffstat (limited to 'Source/cmFileCommand.cxx')
-rw-r--r-- | Source/cmFileCommand.cxx | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx index f86e5e2..34c88ab 100644 --- a/Source/cmFileCommand.cxx +++ b/Source/cmFileCommand.cxx @@ -176,6 +176,9 @@ bool cmFileCommand::InitialPass(std::vector<std::string> const& args, if (subCommand == "LOCK") { return this->HandleLockCommand(args); } + if (subCommand == "SIZE") { + return this->HandleSizeCommand(args); + } std::string e = "does not recognize sub-command " + subCommand; this->SetError(e); @@ -3605,3 +3608,32 @@ bool cmFileCommand::HandleTimestampCommand( return true; } + +bool cmFileCommand::HandleSizeCommand(std::vector<std::string> const& args) +{ + if (args.size() != 3) { + std::ostringstream e; + e << args[0] << " requires a file name and output variable"; + this->SetError(e.str()); + return false; + } + + unsigned int argsIndex = 1; + + const std::string& filename = args[argsIndex++]; + + const std::string& outputVariable = args[argsIndex++]; + + if (!cmSystemTools::FileExists(filename, true)) { + std::ostringstream e; + e << "SIZE requested of path that is not readable " << filename; + this->SetError(e.str()); + return false; + } + + this->Makefile->AddDefinition( + outputVariable, + std::to_string(cmSystemTools::FileLength(filename)).c_str()); + + return true; +} |