diff options
author | 2016-10-04 10:55:43 +0000 | |
---|---|---|
committer | 2016-10-04 12:49:20 +0000 | |
commit | 9f3f6dec5252447c7b0dad59389e057b3a7685bf (patch) | |
tree | d820e8b67989fbc06d621a4918c82f6f03a72450 /third_party/ijar/zip_main.cc | |
parent | 87425681e46e04e48ace077e01907587d271f971 (diff) |
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
Diffstat (limited to 'third_party/ijar/zip_main.cc')
-rw-r--r-- | third_party/ijar/zip_main.cc | 38 |
1 files changed, 28 insertions, 10 deletions
diff --git a/third_party/ijar/zip_main.cc b/third_party/ijar/zip_main.cc index 9759348d39..388bca73e4 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 @@ 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 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 @@ class UnzipProcessor : public ZipExtractorProcessor { } 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 @@ 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; - 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 @@ int extract(char *zipfile, char* exdir, char **files, bool verbose, 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); |