diff options
author | Laszlo Csomor <laszlocsomor@google.com> | 2016-12-01 14:37:46 +0000 |
---|---|---|
committer | Irina Iancu <elenairina@google.com> | 2016-12-01 16:38:15 +0000 |
commit | b8caca0d153a32bb92193c9b3ef33f950c722b16 (patch) | |
tree | 5a69444ed575c12798df6dccd2fe4a2cb74d89a9 /third_party/ijar | |
parent | 8457f3f31af0160c6f8c583e977462d0af091317 (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')
-rw-r--r-- | third_party/ijar/platform_utils.cc | 31 | ||||
-rw-r--r-- | third_party/ijar/platform_utils.h | 8 | ||||
-rw-r--r-- | third_party/ijar/zip_main.cc | 31 |
3 files changed, 41 insertions, 29 deletions
diff --git a/third_party/ijar/platform_utils.cc b/third_party/ijar/platform_utils.cc index a7e3dafaef..8ffcb0640a 100644 --- a/third_party/ijar/platform_utils.cc +++ b/third_party/ijar/platform_utils.cc @@ -132,4 +132,35 @@ string get_cwd() { #endif // COMPILER_MSVC } +bool make_dirs(const char* path, mode_t mode) { +#ifdef COMPILER_MSVC + // TODO(laszlocsomor) 2016-12-01: implement this and other methods, in order + // to close https://github.com/bazelbuild/bazel/issues/2157. + fprintf(stderr, "Not yet implemented on Windows\n"); + return false; +#else // not COMPILER_MSVC + // Directories created must have executable bit set and be owner writeable. + // Otherwise, we cannot write or create any file inside. + mode |= S_IWUSR | S_IXUSR; + 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) && mkdir(path_, mode) < 0) { + fprintf(stderr, "Cannot create folder %s: %s\n", + path_, strerror(errno)); + return false; + } + *pointer = '/'; + } + pointer++; + } + return true; +#endif // COMPILER_MSVC +} + } // namespace devtools_ijar diff --git a/third_party/ijar/platform_utils.h b/third_party/ijar/platform_utils.h index b66a2b1957..8870ae2344 100644 --- a/third_party/ijar/platform_utils.h +++ b/third_party/ijar/platform_utils.h @@ -53,6 +53,14 @@ bool read_file(const char* path, void* buffer, size_t size); // Returns the empty string upon failure and reports the error to stderr. std::string get_cwd(); +// 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 "perm" for creation mode, and are writable and +// openable by the current user. +// Returns true if all directories were created and permissions set. +// Returns false upon failure and reports the error to stderr. +bool make_dirs(const char* path, mode_t perm); + } // namespace devtools_ijar #endif // THIRD_PARTY_IJAR_PLATFORM_UTILS_H_ 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(); } } |