[llvm] r352640 - [llvm-objcopy][NFC] More error propagation (linkToBuildIdDir)
Jordan Rupprecht via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 30 10:13:31 PST 2019
Author: rupprecht
Date: Wed Jan 30 10:13:30 2019
New Revision: 352640
URL: http://llvm.org/viewvc/llvm-project?rev=352640&view=rev
Log:
[llvm-objcopy][NFC] More error propagation (linkToBuildIdDir)
Modified:
llvm/trunk/tools/llvm-objcopy/ELF/ELFObjcopy.cpp
Modified: llvm/trunk/tools/llvm-objcopy/ELF/ELFObjcopy.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objcopy/ELF/ELFObjcopy.cpp?rev=352640&r1=352639&r2=352640&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objcopy/ELF/ELFObjcopy.cpp (original)
+++ llvm/trunk/tools/llvm-objcopy/ELF/ELFObjcopy.cpp Wed Jan 30 10:13:30 2019
@@ -157,13 +157,15 @@ findBuildID(const object::ELFObjectFileB
llvm_unreachable("Bad file format");
}
-static void linkToBuildIdDir(const CopyConfig &Config, StringRef ToLink,
- StringRef Suffix, ArrayRef<uint8_t> BuildIdBytes) {
+static Error linkToBuildIdDir(const CopyConfig &Config, StringRef ToLink,
+ StringRef Suffix,
+ ArrayRef<uint8_t> BuildIdBytes) {
SmallString<128> Path = Config.BuildIdLinkDir;
sys::path::append(Path, llvm::toHex(BuildIdBytes[0], /*LowerCase*/ true));
if (auto EC = sys::fs::create_directories(Path))
- error("cannot create build ID link directory " + Path + ": " +
- EC.message());
+ return createFileError(
+ Path.str(),
+ createStringError(EC, "cannot create build ID link directory"));
sys::path::append(Path,
llvm::toHex(BuildIdBytes.slice(1), /*LowerCase*/ true));
@@ -174,8 +176,10 @@ static void linkToBuildIdDir(const CopyC
sys::fs::remove(Path);
EC = sys::fs::create_hard_link(ToLink, Path);
if (EC)
- error("cannot link " + ToLink + " to " + Path + ": " + EC.message());
+ return createStringError(EC, "cannot link %s to %s", ToLink.data(),
+ Path.data());
}
+ return Error::success();
}
static Error splitDWOToFile(const CopyConfig &Config, const Reader &Reader,
@@ -588,10 +592,12 @@ Error executeObjcopyOnBinary(const CopyC
"build ID is smaller than two bytes."));
}
- if (!Config.BuildIdLinkDir.empty() && Config.BuildIdLinkInput) {
- linkToBuildIdDir(Config, Config.InputFilename,
- Config.BuildIdLinkInput.getValue(), BuildIdBytes);
- }
+ if (!Config.BuildIdLinkDir.empty() && Config.BuildIdLinkInput)
+ if (Error E =
+ linkToBuildIdDir(Config, Config.InputFilename,
+ Config.BuildIdLinkInput.getValue(), BuildIdBytes))
+ return E;
+
if (Error E = handleArgs(Config, *Obj, Reader, OutputElfType))
return E;
std::unique_ptr<Writer> Writer =
@@ -600,10 +606,12 @@ Error executeObjcopyOnBinary(const CopyC
return E;
if (Error E = Writer->write())
return E;
- if (!Config.BuildIdLinkDir.empty() && Config.BuildIdLinkOutput) {
- linkToBuildIdDir(Config, Config.OutputFilename,
- Config.BuildIdLinkOutput.getValue(), BuildIdBytes);
- }
+ if (!Config.BuildIdLinkDir.empty() && Config.BuildIdLinkOutput)
+ if (Error E =
+ linkToBuildIdDir(Config, Config.OutputFilename,
+ Config.BuildIdLinkOutput.getValue(), BuildIdBytes))
+ return E;
+
return Error::success();
}
More information about the llvm-commits
mailing list