Thrift: Create directories with more permissive modes.
Summary:
How many times has no one else been able to use your awesome Python script
because the Thrift generated files are in a directory that they can't access?
Never again! We now create directories with mode 0777.
Of course, your process umask will ensure that they are actually created
with mode 0755. (This is how the mkdir command works.)
Reviewed By: mcslee
Test Plan:
Rebuilt thrift, then did this:
dreiss@dreiss-vmware:dir_mode:thrift/test$ rm -rf gen-*
dreiss@dreiss-vmware:dir_mode:thrift/test$ thrift -cpp -java -php -py ThriftTest.thrift
dreiss@dreiss-vmware:dir_mode:thrift/test$ ls -ld gen-*
drwx------ 2 dreiss dreiss 4096 2007-10-18 12:20 gen-cpp
drwx------ 3 dreiss dreiss 4096 2007-10-18 12:20 gen-java
drwx------ 2 dreiss dreiss 4096 2007-10-18 12:20 gen-php
drwx------ 3 dreiss dreiss 4096 2007-10-18 12:20 gen-py
dreiss@dreiss-vmware:dir_mode:thrift/test$ rm -rf gen-*
dreiss@dreiss-vmware:dir_mode:thrift/test$ ../compiler/cpp/thrift -cpp -java -php -py ThriftTest.thrift
dreiss@dreiss-vmware:dir_mode:thrift/test$ ls -ld gen-*
drwxr-xr-x 2 dreiss dreiss 4096 2007-10-18 12:20 gen-cpp
drwxr-xr-x 3 dreiss dreiss 4096 2007-10-18 12:20 gen-java
drwxr-xr-x 2 dreiss dreiss 4096 2007-10-18 12:20 gen-php
drwxr-xr-x 3 dreiss dreiss 4096 2007-10-18 12:20 gen-py
dreiss@dreiss-vmware:dir_mode:thrift/test$
Revert Plan: ok
Other Notes:
With some help from external contributor Ben Maurer.
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665317 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/compiler/cpp/src/generate/t_cocoa_generator.cc b/compiler/cpp/src/generate/t_cocoa_generator.cc
index 728cd49..6cb86a2 100644
--- a/compiler/cpp/src/generate/t_cocoa_generator.cc
+++ b/compiler/cpp/src/generate/t_cocoa_generator.cc
@@ -16,7 +16,7 @@
*/
void t_cocoa_generator::init_generator() {
// Make output directory
- mkdir(get_out_dir().c_str(), S_IREAD | S_IWRITE | S_IEXEC);
+ mkdir(get_out_dir().c_str(), S_IRWXU | S_IRWXG | S_IRWXO);
cocoa_prefix_ = program_->get_cocoa_prefix();
// we have a .h header file...
diff --git a/compiler/cpp/src/generate/t_cpp_generator.cc b/compiler/cpp/src/generate/t_cpp_generator.cc
index 3482320..b68d2fc 100644
--- a/compiler/cpp/src/generate/t_cpp_generator.cc
+++ b/compiler/cpp/src/generate/t_cpp_generator.cc
@@ -20,7 +20,7 @@
*/
void t_cpp_generator::init_generator() {
// Make output directory
- mkdir(get_out_dir().c_str(), S_IREAD | S_IWRITE | S_IEXEC);
+ mkdir(get_out_dir().c_str(), S_IRWXU | S_IRWXG | S_IRWXO);
// Make output file
string f_types_name = get_out_dir()+program_name_+"_types.h";
diff --git a/compiler/cpp/src/generate/t_erl_generator.cc b/compiler/cpp/src/generate/t_erl_generator.cc
index 3e3f966..1783bba 100644
--- a/compiler/cpp/src/generate/t_erl_generator.cc
+++ b/compiler/cpp/src/generate/t_erl_generator.cc
@@ -20,7 +20,7 @@
*/
void t_erl_generator::init_generator() {
// Make output directory
- mkdir(get_out_dir().c_str(), S_IREAD | S_IWRITE | S_IEXEC);
+ mkdir(get_out_dir().c_str(), S_IRWXU | S_IRWXG | S_IRWXO);
// setup export lines
export_lines_first_ = true;
diff --git a/compiler/cpp/src/generate/t_hs_generator.cc b/compiler/cpp/src/generate/t_hs_generator.cc
index 03d62a4..8746ba4 100644
--- a/compiler/cpp/src/generate/t_hs_generator.cc
+++ b/compiler/cpp/src/generate/t_hs_generator.cc
@@ -72,7 +72,7 @@
*/
void t_hs_generator::init_generator() {
// Make output directory
- mkdir(get_out_dir().c_str(), S_IREAD | S_IWRITE | S_IEXEC);
+ mkdir(get_out_dir().c_str(), S_IRWXU | S_IRWXG | S_IRWXO);
// Make output file
diff --git a/compiler/cpp/src/generate/t_java_generator.cc b/compiler/cpp/src/generate/t_java_generator.cc
index a6d2c4a..8f992b4 100644
--- a/compiler/cpp/src/generate/t_java_generator.cc
+++ b/compiler/cpp/src/generate/t_java_generator.cc
@@ -18,7 +18,7 @@
*/
void t_java_generator::init_generator() {
// Make output directory
- mkdir(get_out_dir().c_str(), S_IREAD | S_IWRITE | S_IEXEC);
+ mkdir(get_out_dir().c_str(), S_IRWXU | S_IRWXG | S_IRWXO);
package_name_ = program_->get_java_package();
string dir = package_name_;
@@ -26,12 +26,12 @@
string::size_type loc;
while ((loc = dir.find(".")) != string::npos) {
subdir = subdir + "/" + dir.substr(0, loc);
- mkdir(subdir.c_str(), S_IREAD | S_IWRITE | S_IEXEC);
+ mkdir(subdir.c_str(), S_IRWXU | S_IRWXG | S_IRWXO);
dir = dir.substr(loc+1);
}
if (dir.size() > 0) {
subdir = subdir + "/" + dir;
- mkdir(subdir.c_str(), S_IREAD | S_IWRITE | S_IEXEC);
+ mkdir(subdir.c_str(), S_IRWXU | S_IRWXG | S_IRWXO);
}
package_dir_ = subdir;
diff --git a/compiler/cpp/src/generate/t_ocaml_generator.cc b/compiler/cpp/src/generate/t_ocaml_generator.cc
index 7bfe4fd..8bf6457 100644
--- a/compiler/cpp/src/generate/t_ocaml_generator.cc
+++ b/compiler/cpp/src/generate/t_ocaml_generator.cc
@@ -72,7 +72,7 @@
*/
void t_ocaml_generator::init_generator() {
// Make output directory
- mkdir(get_out_dir().c_str(), S_IREAD | S_IWRITE | S_IEXEC);
+ mkdir(get_out_dir().c_str(), S_IRWXU | S_IRWXG | S_IRWXO);
// Make output file
string f_types_name = get_out_dir()+program_name_+"_types.ml";
diff --git a/compiler/cpp/src/generate/t_perl_generator.cc b/compiler/cpp/src/generate/t_perl_generator.cc
index edec010..ee6b5b4 100644
--- a/compiler/cpp/src/generate/t_perl_generator.cc
+++ b/compiler/cpp/src/generate/t_perl_generator.cc
@@ -18,13 +18,13 @@
*/
void t_perl_generator::init_generator() {
// Make output directory
- mkdir(get_out_dir().c_str(), S_IREAD | S_IWRITE | S_IEXEC);
+ mkdir(get_out_dir().c_str(), S_IRWXU | S_IRWXG | S_IRWXO);
string outdir = get_out_dir();
std::string ns = program_->get_perl_package();
if (ns.length() > 0) {
outdir += ns + "/";
- mkdir(outdir.c_str(), S_IREAD | S_IWRITE | S_IEXEC);
+ mkdir(outdir.c_str(), S_IRWXU | S_IRWXG | S_IRWXO);
}
// Make output file
diff --git a/compiler/cpp/src/generate/t_php_generator.cc b/compiler/cpp/src/generate/t_php_generator.cc
index 62900a0..ba0e189 100644
--- a/compiler/cpp/src/generate/t_php_generator.cc
+++ b/compiler/cpp/src/generate/t_php_generator.cc
@@ -18,7 +18,7 @@
*/
void t_php_generator::init_generator() {
// Make output directory
- mkdir(get_out_dir().c_str(), S_IREAD | S_IWRITE | S_IEXEC);
+ mkdir(get_out_dir().c_str(), S_IRWXU | S_IRWXG | S_IRWXO);
// Make output file
string f_types_name = get_out_dir()+program_name_+"_types.php";
diff --git a/compiler/cpp/src/generate/t_py_generator.cc b/compiler/cpp/src/generate/t_py_generator.cc
index 3dd3892..d682bee 100644
--- a/compiler/cpp/src/generate/t_py_generator.cc
+++ b/compiler/cpp/src/generate/t_py_generator.cc
@@ -24,7 +24,7 @@
package_dir_ = get_out_dir();
while (true) {
// TODO: Do better error checking here.
- mkdir(package_dir_.c_str(), S_IREAD | S_IWRITE | S_IEXEC);
+ mkdir(package_dir_.c_str(), S_IRWXU | S_IRWXG | S_IRWXO);
std::ofstream init_py((package_dir_+"/__init__.py").c_str());
init_py.close();
if (module.empty()) {
diff --git a/compiler/cpp/src/generate/t_rb_generator.cc b/compiler/cpp/src/generate/t_rb_generator.cc
index b68ef30..54b5005 100644
--- a/compiler/cpp/src/generate/t_rb_generator.cc
+++ b/compiler/cpp/src/generate/t_rb_generator.cc
@@ -19,7 +19,7 @@
*/
void t_rb_generator::init_generator() {
// Make output directory
- mkdir(get_out_dir().c_str(), S_IREAD | S_IWRITE | S_IEXEC);
+ mkdir(get_out_dir().c_str(), S_IRWXU | S_IRWXG | S_IRWXO);
// Make output file
string f_types_name = get_out_dir()+program_name_+"_types.rb";
diff --git a/compiler/cpp/src/generate/t_xsd_generator.cc b/compiler/cpp/src/generate/t_xsd_generator.cc
index 0910048..04645d2 100644
--- a/compiler/cpp/src/generate/t_xsd_generator.cc
+++ b/compiler/cpp/src/generate/t_xsd_generator.cc
@@ -12,7 +12,7 @@
void t_xsd_generator::init_generator() {
// Make output directory
- mkdir(get_out_dir().c_str(), S_IREAD | S_IWRITE | S_IEXEC);
+ mkdir(get_out_dir().c_str(), S_IRWXU | S_IRWXG | S_IRWXO);
// Make output file
string f_php_name = get_out_dir()+program_->get_name()+"_xsd.php";