Commit 14763ddd authored by Sébastien Luttringer's avatar Sébastien Luttringer
Browse files

chrights doesn't raise error by default

If a chown,chmod,chgrp or utime call fail, it doesn't raise an error.
Used by extract_file_payload to have same behaviour than tar when file
is owned by root by example.
parent 23a3b22e
Loading
Loading
Loading
Loading
+22 −5
Original line number Diff line number Diff line
@@ -325,18 +325,35 @@ def mkdir(path, uid=None, gid=None, mode=None):
    makedirs(path)
    chrights(path, uid, gid, mode)

def chrights(path, uid=None, gid=None, mode=None, mtime=None):
def chrights(path, uid=None, gid=None, mode=None, mtime=None, strict=False):
    '''
    Set rights on a file
    If strict is True, raise error if change right fail
    '''
    if uid is not None:
        try:
            chown(path, uid, -1)
        except OSError:
            if strict:
                raise
    if gid is not None:
        try:
            chown(path, -1, gid)
        except OSError:
            if strict:
                raise
    if mode is not None:
        try:
            chmod(path, mode)
        except OSError:
            if strict:
                raise
    if mtime is not None:
        try:
            utime(path, (mtime, mtime))
        except OSError:
            if strict:
                raise

def pathtype(path):
    '''