aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/tools/singlejar/output_jar.cc
diff options
context:
space:
mode:
authorGravatar cushon <cushon@google.com>2017-04-21 04:45:22 +0200
committerGravatar Vladimir Moskva <vladmos@google.com>2017-04-24 16:50:20 +0200
commit272c8f631341c2841a108ca28d394e4a0f7d6ff0 (patch)
treeedb403444bde9a47b50fee3d7fd950d7269dc44e /src/tools/singlejar/output_jar.cc
parent3da1d729ed09f9046ed21a5546a671de3a70e3fe (diff)
Support directories in --resources
PiperOrigin-RevId: 153787279
Diffstat (limited to 'src/tools/singlejar/output_jar.cc')
-rw-r--r--src/tools/singlejar/output_jar.cc28
1 files changed, 22 insertions, 6 deletions
diff --git a/src/tools/singlejar/output_jar.cc b/src/tools/singlejar/output_jar.cc
index 1b19de8bb3..80eaede63a 100644
--- a/src/tools/singlejar/output_jar.cc
+++ b/src/tools/singlejar/output_jar.cc
@@ -830,6 +830,15 @@ bool OutputJar::Close() {
return true;
}
+bool IsDir(const std::string &path) {
+ struct stat st;
+ if (stat(path.c_str(), &st)) {
+ diag_warn("%s:%d: stat %s:", __FILE__, __LINE__, path.c_str());
+ return false;
+ }
+ return S_ISDIR(st.st_mode);
+}
+
void OutputJar::ClasspathResource(const std::string &resource_name,
const std::string &resource_path) {
if (known_members_.count(resource_name)) {
@@ -845,14 +854,21 @@ void OutputJar::ClasspathResource(const std::string &resource_name,
}
}
MappedFile mapped_file;
- if (!mapped_file.Open(resource_path)) {
+ if (mapped_file.Open(resource_path)) {
+ Concatenator *classpath_resource = new Concatenator(resource_name);
+ classpath_resource->Append(
+ reinterpret_cast<const char *>(mapped_file.start()),
+ mapped_file.size());
+ classpath_resources_.emplace_back(classpath_resource);
+ known_members_.emplace(resource_name, EntryInfo{classpath_resource});
+ } else if (IsDir(resource_path)) {
+ // add an empty entry for the directory so its path ends up in the
+ // manifest
+ classpath_resources_.emplace_back(new Concatenator(resource_name + "/"));
+ known_members_.emplace(resource_name, EntryInfo{&null_combiner_});
+ } else {
diag_err(1, "%s:%d: %s", __FILE__, __LINE__, resource_path.c_str());
}
- Concatenator *classpath_resource = new Concatenator(resource_name);
- classpath_resource->Append(
- reinterpret_cast<const char *>(mapped_file.start()), mapped_file.size());
- classpath_resources_.emplace_back(classpath_resource);
- known_members_.emplace(resource_name, EntryInfo{classpath_resource});
}
ssize_t OutputJar::AppendFile(int in_fd, off_t offset, size_t count) {