Rollback of commit a6b4cbbd4a4bbb42eefe8fb0e646cd30780394e4.
*** Reason for rollback ***
Other projects may depend on Ijar without wanting to depend on Bazel.
*** Original change description ***
Ijar: use utilities from Bazel's source
Remove a duplicate implementation of JoinPath.
--
MOS_MIGRATED_REVID=135088616
diff --git a/src/main/cpp/util/BUILD b/src/main/cpp/util/BUILD
index 3129c52..3602055 100644
--- a/src/main/cpp/util/BUILD
+++ b/src/main/cpp/util/BUILD
@@ -37,10 +37,7 @@
name = "file",
srcs = ["file.cc"],
hdrs = ["file.h"],
- visibility = [
- "//src/tools/singlejar:__pkg__",
- "//third_party/ijar:__pkg__",
- ],
+ visibility = ["//src/tools/singlejar:__pkg__"],
deps = [
":blaze_exit_code",
":errors",
diff --git a/third_party/ijar/BUILD b/third_party/ijar/BUILD
index f6d7e49..63d1182 100644
--- a/third_party/ijar/BUILD
+++ b/third_party/ijar/BUILD
@@ -44,10 +44,7 @@
name = "zipper",
srcs = ["zip_main.cc"],
visibility = ["//visibility:public"],
- deps = [
- ":zip",
- "//src/main/cpp/util:file",
- ],
+ deps = [":zip"],
)
cc_binary(
diff --git a/third_party/ijar/zip_main.cc b/third_party/ijar/zip_main.cc
index 9759348..388bca7 100644
--- a/third_party/ijar/zip_main.cc
+++ b/third_party/ijar/zip_main.cc
@@ -32,7 +32,6 @@
#include <set>
#include <string>
-#include "src/main/cpp/util/file.h"
#include "third_party/ijar/zip.h"
namespace devtools_ijar {
@@ -52,7 +51,7 @@
// 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 std::string& output_root, char **files, bool verbose,
+ UnzipProcessor(const char *output_root, char **files, bool verbose,
bool extract) : output_root_(output_root),
verbose_(verbose),
extract_(extract) {
@@ -78,12 +77,30 @@
}
private:
- const std::string& output_root_;
+ const char *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.
@@ -123,16 +140,17 @@
printf("%c %o %s\n", isdir ? 'd' : 'f', perm, filename);
}
if (extract_) {
+ char path[PATH_MAX];
int fd;
- std::string path = blaze_util::JoinPath(output_root_, filename);
+ concat_path(path, PATH_MAX, 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.c_str(), perm | S_IWUSR | S_IXUSR);
+ mkdirs(path, perm | S_IWUSR | S_IXUSR);
if (!isdir) {
- fd = open(path.c_str(), O_CREAT | O_WRONLY, perm);
+ fd = open(path, O_CREAT | O_WRONLY, perm);
if (fd < 0) {
fprintf(stderr, "Cannot open file %s for writing: %s\n",
- path.c_str(), strerror(errno));
+ path, strerror(errno));
abort();
}
SYSCALL(write(fd, data, size));
@@ -180,11 +198,11 @@
return -1;
}
- std::string output_root;
+ char output_root[PATH_MAX];
if (exdir != NULL) {
- output_root = blaze_util::JoinPath(cwd, exdir);
+ concat_path(output_root, PATH_MAX, cwd, exdir);
} else {
- output_root = cwd;
+ strncpy(output_root, cwd, PATH_MAX);
}
UnzipProcessor processor(output_root, files, verbose, extract);