Reputation: 11
I have a shared git repository creation script that I've been writing in Python 3.2.3, and while the vast majority of the script is working, and almost production ready (still have some securing to do), I've been running into an awkward bug which, for the life of me, I cannot figure out.
During my iterative change mode section:
try:
if (args.debug):
print('Recursively changing the access mode of target directory ' + full_path +
' to ' oct(stat.S_IRWXU | stat.S_IRWXG | stat.S_IROTH) + '.')
if (args.debug):
print('setting ' + full_path +
' to stat.S_IRWXU | stat.S_IRWXG | stat.S_IROTH ')
os.chmod(full_path, stat.S_IRWXU | stat.S_IRWXG | stat.S_IROTH)
for root, dirs, files in os.walk(full_path):
for spam in dirs:
if (args.debug):
print('spam in dirs: ' + spam +
'; stat.S_IRWXU | stat.S_IRWXG | stat.S_IROTH: ')
os.chmod(os.path.join(root, spam), stat.S_IRWXU | stat.S_IRWXG | stat.S_IROTH)
for eggs in files:
if (args.debug):
print('eggs in files: ' + eggs +
'; stat.S_IRWXU | stat.S_IRWXG | stat.S_IROTH: ')
os.chmod(os.path.join(root, eggs), stat.S_IRWXU | stat.S_IRWXG | stat.S_IROTH)
except OSError as e:
if (args.debug):
print('OSError raised during recursive chmod ' +
oct(stat.S_IRWXU | stat.S_IRWXG | stat.S_IROTH) + ' setting. ' +
'Removing the partially created repository.')
shutil.rmtree(full_path)
I have been running into a problem -- it's not correctly setting my directory permissions correctly. In fact, it has been doing the complete opposite; it has been stripping all my directory permissions. The directory tree resembles this after running the script:
d-----S--- 7 mat users 4096 Jul 3 23:10 test
ls: cannot open directory /home/mat/git/test: Permission denied
(the setgid bit was set in a later, working loop) Obviously, I'm missing something, but I can't exactly tell what, as I am using the stat module's constants. and bitwise ORing them together to get the 0o744 value I'm looking for.
Before anyone suggests that I use an octal literal instead of the stat module's constants, I have tried that, with the same result.
Any help would be grand. ~ M
Upvotes: 1
Views: 572
Reputation: 70162
(As per comments, posting this as an answer for completeness, since this was the issue.)
Since the rest of your code looks ok, it seems like your setgid
loop might be clearing your earlier permissions.
Upvotes: 1