aboutsummaryrefslogtreecommitdiffhomepage
path: root/third_party/ijar
diff options
context:
space:
mode:
authorGravatar Laszlo Csomor <laszlocsomor@google.com>2016-09-30 13:44:05 +0000
committerGravatar Yun Peng <pcloudy@google.com>2016-09-30 14:13:06 +0000
commita6b4cbbd4a4bbb42eefe8fb0e646cd30780394e4 (patch)
tree49ddea9051525fa8dbdbda6028558c3c174b9b13 /third_party/ijar
parentfd158cb0c2e85cd909e429d6658216fef521a60c (diff)
Ijar: use utilities from Bazel's source
Remove a duplicate implementation of JoinPath. -- MOS_MIGRATED_REVID=134778185
Diffstat (limited to 'third_party/ijar')
-rw-r--r--third_party/ijar/BUILD5
-rw-r--r--third_party/ijar/zip_main.cc38
2 files changed, 14 insertions, 29 deletions
diff --git a/third_party/ijar/BUILD b/third_party/ijar/BUILD
index 63d1182e63..f6d7e49e87 100644
--- a/third_party/ijar/BUILD
+++ b/third_party/ijar/BUILD
@@ -44,7 +44,10 @@ cc_binary(
name = "zipper",
srcs = ["zip_main.cc"],
visibility = ["//visibility:public"],
- deps = [":zip"],
+ deps = [
+ ":zip",
+ "//src/main/cpp/util:file",
+ ],
)
cc_binary(
diff --git a/third_party/ijar/zip_main.cc b/third_party/ijar/zip_main.cc
index 388bca73e4..9759348d39 100644
--- a/third_party/ijar/zip_main.cc
+++ b/third_party/ijar/zip_main.cc
@@ -32,6 +32,7 @@
#include <set>
#include <string>
+#include "src/main/cpp/util/file.h"
#include "third_party/ijar/zip.h"
namespace devtools_ijar {
@@ -51,7 +52,7 @@ class UnzipProcessor : public ZipExtractorProcessor {
// Create a processor who will extract the given files (or all files if NULL)
// into output_root if "extract" is set to true and will print the list of
// files and their unix modes if "verbose" is set to true.
- UnzipProcessor(const char *output_root, char **files, bool verbose,
+ UnzipProcessor(const std::string& output_root, char **files, bool verbose,
bool extract) : output_root_(output_root),
verbose_(verbose),
extract_(extract) {
@@ -77,30 +78,12 @@ class UnzipProcessor : public ZipExtractorProcessor {
}
private:
- const char *output_root_;
+ const std::string& output_root_;
const bool verbose_;
const bool extract_;
std::set<std::string> file_names;
};
-// Concatene 2 path, path1 and path2, using / as a directory separator and
-// puting the result in "out". "size" specify the size of the output buffer
-void concat_path(char* out, const size_t size,
- const char *path1, const char *path2) {
- int len1 = strlen(path1);
- size_t l = len1;
- strncpy(out, path1, size - 1);
- out[size-1] = 0;
- if (l < size - 1 && path1[len1] != '/' && path2[0] != '/') {
- out[l] = '/';
- l++;
- out[l] = 0;
- }
- if (l < size - 1) {
- strncat(out, path2, size - 1 - l);
- }
-}
-
// Do a recursive mkdir of all folders of path except the last path
// segment (if path ends with a / then the last path segment is empty).
// All folders are created using "mode" for creation mode.
@@ -140,17 +123,16 @@ void UnzipProcessor::Process(const char* filename, const u4 attr,
printf("%c %o %s\n", isdir ? 'd' : 'f', perm, filename);
}
if (extract_) {
- char path[PATH_MAX];
int fd;
- concat_path(path, PATH_MAX, output_root_, filename);
+ std::string path = blaze_util::JoinPath(output_root_, filename);
// Directories created must have executable bit set and be owner writeable.
// Otherwise, we cannot write or create any file inside.
- mkdirs(path, perm | S_IWUSR | S_IXUSR);
+ mkdirs(path.c_str(), perm | S_IWUSR | S_IXUSR);
if (!isdir) {
- fd = open(path, O_CREAT | O_WRONLY, perm);
+ fd = open(path.c_str(), O_CREAT | O_WRONLY, perm);
if (fd < 0) {
fprintf(stderr, "Cannot open file %s for writing: %s\n",
- path, strerror(errno));
+ path.c_str(), strerror(errno));
abort();
}
SYSCALL(write(fd, data, size));
@@ -198,11 +180,11 @@ int extract(char *zipfile, char* exdir, char **files, bool verbose,
return -1;
}
- char output_root[PATH_MAX];
+ std::string output_root;
if (exdir != NULL) {
- concat_path(output_root, PATH_MAX, cwd, exdir);
+ output_root = blaze_util::JoinPath(cwd, exdir);
} else {
- strncpy(output_root, cwd, PATH_MAX);
+ output_root = cwd;
}
UnzipProcessor processor(output_root, files, verbose, extract);