def testMakedirs(self):
tmpdir = tempfile.mkdtemp()
# make the parent directory read-write
os.chmod(tmpdir, stat.S_IRWXU)
fpath = os.path.join(tmpdir, "f")
fopath = os.path.join(fpath, "o")
foopath = os.path.join(fopath, "o")
# make the leaf, and ONLY the leaf read-only
act = action.fromstr("dir path={0}".format(foopath))
act.makedirs(foopath, mode = stat.S_IREAD)
# Now make sure the directories leading up the leaf
# are read-write, and the leaf is readonly.
assert(os.stat(tmpdir).st_mode & (stat.S_IREAD | stat.S_IWRITE) != 0)
assert(os.stat(fpath).st_mode & (stat.S_IREAD | stat.S_IWRITE) != 0)
assert(os.stat(fopath).st_mode & (stat.S_IREAD | stat.S_IWRITE) != 0)
assert(os.stat(foopath).st_mode & stat.S_IREAD != 0)
assert(os.stat(foopath).st_mode & stat.S_IWRITE == 0)
# change it back to read/write so we can delete it
os.chmod(foopath, stat.S_IRWXU)
shutil.rmtree(tmpdir)
评论列表
文章目录