Revision 9c2b3a70 lib/utils/io.py
b/lib/utils/io.py | ||
---|---|---|
300 | 300 |
dir_gid=None): |
301 | 301 |
"""Renames a file. |
302 | 302 |
|
303 |
This just creates the very least directory if it does not exist and C{mkdir} |
|
304 |
is set to true. |
|
305 |
|
|
303 | 306 |
@type old: string |
304 | 307 |
@param old: Original path |
305 | 308 |
@type new: string |
... | ... | |
323 | 326 |
if mkdir and err.errno == errno.ENOENT: |
324 | 327 |
# Create directory and try again |
325 | 328 |
dir_path = os.path.dirname(new) |
326 |
Makedirs(dir_path, mode=mkdir_mode) |
|
327 |
if not (dir_uid is None or dir_gid is None): |
|
328 |
os.chown(dir_path, dir_uid, dir_gid) |
|
329 |
MakeDirWithPerm(dir_path, mkdir_mode, dir_uid, dir_gid) |
|
329 | 330 |
|
330 | 331 |
return os.rename(old, new) |
331 | 332 |
|
332 | 333 |
raise |
333 | 334 |
|
334 | 335 |
|
335 |
def EnforcePermission(path, mode, uid=-1, gid=-1, must_exist=True,
|
|
336 |
def EnforcePermission(path, mode, uid=None, gid=None, must_exist=True,
|
|
336 | 337 |
_chmod_fn=os.chmod, _chown_fn=os.chown, _stat_fn=os.stat): |
337 | 338 |
"""Enforces that given path has given permissions. |
338 | 339 |
|
... | ... | |
346 | 347 |
|
347 | 348 |
""" |
348 | 349 |
logging.debug("Checking %s", path) |
350 |
|
|
351 |
# chown takes -1 if you want to keep one part of the ownership, however |
|
352 |
# None is Python standard for that. So we remap them here. |
|
353 |
if uid is None: |
|
354 |
uid = -1 |
|
355 |
if gid is None: |
|
356 |
gid = -1 |
|
357 |
|
|
349 | 358 |
try: |
350 | 359 |
st = _stat_fn(path) |
351 | 360 |
|
Also available in: Unified diff