aboutsummaryrefslogtreecommitdiffhomepage
path: root/third_party/ijar/zip_main.cc
diff options
context:
space:
mode:
authorGravatar Laszlo Csomor <laszlocsomor@google.com>2016-12-01 14:37:46 +0000
committerGravatar Irina Iancu <elenairina@google.com>2016-12-01 16:38:15 +0000
commitb8caca0d153a32bb92193c9b3ef33f950c722b16 (patch)
tree5a69444ed575c12798df6dccd2fe4a2cb74d89a9 /third_party/ijar/zip_main.cc
parent8457f3f31af0160c6f8c583e977462d0af091317 (diff)
Ijar: extract MakeDirs to platform_utils
zip_main.cc no longer needs <unistd.h>. This change takes us closer to compiling ijar, thus Bazel, with MSVC. See https://github.com/bazelbuild/bazel/issues/2157 See https://github.com/bazelbuild/bazel/issues/2107 -- MOS_MIGRATED_REVID=140724421
Diffstat (limited to 'third_party/ijar/zip_main.cc')
-rw-r--r--third_party/ijar/zip_main.cc31
1 files changed, 2 insertions, 29 deletions
diff --git a/third_party/ijar/zip_main.cc b/third_party/ijar/zip_main.cc
index 578d64c354..74853dc757 100644
--- a/third_party/ijar/zip_main.cc
+++ b/third_party/ijar/zip_main.cc
@@ -94,31 +94,6 @@ void concat_path(char* out, const size_t size,
}
}
-// 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.
-void mkdirs(const char *path, mode_t mode) {
- char path_[PATH_MAX];
- Stat file_stat;
- strncpy(path_, path, PATH_MAX);
- path_[PATH_MAX-1] = 0;
- char *pointer = path_;
- while ((pointer = strchr(pointer, '/')) != NULL) {
- if (path_ != pointer) { // skip leading slash
- *pointer = 0;
- if (!stat_file(path_, &file_stat)) {
- if (mkdir(path_, mode) < 0) {
- fprintf(stderr, "Cannot create folder %s: %s\n",
- path_, strerror(errno));
- abort();
- }
- }
- *pointer = '/';
- }
- pointer++;
- }
-}
-
void UnzipProcessor::Process(const char* filename, const u4 attr,
const u1* data, const size_t size) {
mode_t mode = zipattr_to_mode(attr);
@@ -135,10 +110,8 @@ void UnzipProcessor::Process(const char* filename, const u4 attr,
if (extract_) {
char path[PATH_MAX];
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, perm | S_IWUSR | S_IXUSR);
- if (!isdir && !write_file(path, perm, data, size)) {
+ if (!make_dirs(path, perm) ||
+ (!isdir && !write_file(path, perm, data, size))) {
abort();
}
}