def untar_file(filename, location):<EOL>
ensure_dir(location)<EOL>if filename.lower().endswith('<STR_LIT>') or filename.lower().endswith('<STR_LIT>'):<EOL><INDENT>mode = '<STR_LIT>'<EOL><DEDENT>elif filename.lower().endswith(BZ2_EXTENSIONS):<EOL><INDENT>mode = '<STR_LIT>'<EOL><DEDENT>elif filename.lower().endswith(XZ_EXTENSIONS):<EOL><INDENT>mode = '<STR_LIT>'<EOL><DEDENT>elif filename.lower().endswith('<STR_LIT>'):<EOL><INDENT>mode = '<STR_LIT:r>'<EOL><DEDENT>else:<EOL><INDENT>logger.warning(<EOL>'<STR_LIT>', filename,<EOL>)<EOL>mode = '<STR_LIT>'<EOL><DEDENT>tar = tarfile.open(filename, mode)<EOL>try:<EOL><INDENT>leading = has_leading_dir([<EOL>member.name for member in tar.getmembers()<EOL>])<EOL>for member in tar.getmembers():<EOL><INDENT>fn = member.name<EOL>if leading:<EOL><INDENT>fn = split_leading_dir(fn)[<NUM_LIT:1>]  <EOL><DEDENT>path = os.path.join(location, fn)<EOL>if member.isdir():<EOL><INDENT>ensure_dir(path)<EOL><DEDENT>elif member.issym():<EOL><INDENT>try:<EOL><INDENT>tar._extract_member(member, path)  <EOL><DEDENT>except Exception as exc:<EOL><INDENT>logger.warning(<EOL>'<STR_LIT>',<EOL>filename, member.name, exc,<EOL>)<EOL>continue<EOL><DEDENT><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>fp = tar.extractfile(member)<EOL><DEDENT>except (KeyError, AttributeError) as exc:<EOL><INDENT>logger.warning(<EOL>'<STR_LIT>',<EOL>filename, member.name, exc,<EOL>)<EOL>continue<EOL><DEDENT>ensure_dir(os.path.dirname(path))<EOL>with open(path, '<STR_LIT:wb>') as destfp:<EOL><INDENT>shutil.copyfileobj(fp, destfp)<EOL><DEDENT>fp.close()<EOL>tar.utime(member, path)  <EOL>if member.mode & <NUM_LIT>:<EOL><INDENT>os.chmod(path, (<NUM_LIT> - current_umask() | <NUM_LIT>))<EOL><DEDENT><DEDENT><DEDENT><DEDENT>finally:<EOL><INDENT>tar.close()<EOL><DEDENT>
Untar the file (with path `filename`) to the destination `location`.
All files are written based on system defaults and umask (i.e. permissions
are not preserved), except that regular file members with any execute
permissions (user, group, or world) have "chmod +x" applied after being
written.  Note that for windows, any execute changes using os.chmod are
no-ops per the python docs.