New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

verify_directory should respect umask #101

Closed
sqlalchemy-bot opened this Issue Feb 10, 2009 · 8 comments

Comments

Projects
None yet
1 participant
@sqlalchemy-bot

sqlalchemy-bot commented Feb 10, 2009

Migrated issue, originally created by Anonymous

Currently util.verify_directory is hardcoding the mode of 0750 in its call to os.makedirs. The following patch checks the umask and passes mode along accordingly:

Index: lib/mako/util.py
===================================================================
--- lib/mako/util.py    (revision 439)
+++ lib/mako/util.py    (working copy)
@@ -17,6 +17,7 @@
     from StringIO import StringIO
 
 import codecs, re, weakref, os, time
+import subprocess
 
 try:
     import threading
@@ -38,7 +39,10 @@
     while not os.path.exists(dir):
         try:
             tries += 1
-            os.makedirs(dir, 0750)
+            umask, _ = subprocess.Popen(['sh', '-c', 'umask'], stdout=subprocess.PIPE).communicate()
+            umask = int(umask, 8)
+            mode = int(oct(0777 ^ umask), 8)
+            os.makedirs(dir, mode)
         except:
             if tries > 5:
                 raise
@sqlalchemy-bot

This comment has been minimized.

sqlalchemy-bot commented Feb 10, 2009

Anonymous wrote:

looks like this code was lifted from beaker.util. filed a [http://pylonshq.com/project/pylonshq/ticket/567 corresponding ticket] in the pylons trac.

@sqlalchemy-bot

This comment has been minimized.

sqlalchemy-bot commented Feb 11, 2009

Anonymous wrote:

note: the line

mode = int(oct(0777 ^ umask), 8)

could of course be simplified to

mode = 0777 ^ umask

if you're into the whole brevity thing.

@sqlalchemy-bot

This comment has been minimized.

sqlalchemy-bot commented Feb 11, 2009

Anonymous wrote:

alternatively it may be preferable to effect more permissions-sensitive behavior via configuration options mako.umask or some such.

@sqlalchemy-bot

This comment has been minimized.

sqlalchemy-bot commented Feb 11, 2009

Anonymous wrote:

discussed with zzzeek in #pylons, decided this is really a [http://bugs.python.org/issue5220 python bug]. a workaround like the above (though preferably a more platform independent one) can be used if desired until this is fixed in python.

@sqlalchemy-bot

This comment has been minimized.

sqlalchemy-bot commented Feb 11, 2009

Anonymous wrote:

Replying to [comment:4 guest]:

decided this is really a [http://bugs.python.org/issue5220 python bug]
scratch that. it seems like we were misunderstanding the mode parameter (see response in the python ticket). otherwise why pass 0750? it effectively throws out part of the umask.

@sqlalchemy-bot

This comment has been minimized.

sqlalchemy-bot commented Feb 14, 2009

Michael Bayer (@zzzeek) wrote:

I think we decided here to just use 0775 for the mask.

@sqlalchemy-bot

This comment has been minimized.

sqlalchemy-bot commented Mar 19, 2009

Michael Bayer (@zzzeek) wrote:

43b362d

@sqlalchemy-bot

This comment has been minimized.

sqlalchemy-bot commented Mar 19, 2009

Changes by Michael Bayer (@zzzeek):

  • changed status to closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment