def pull(directory):
"""
Pulls latest changes with the user rights that owns the folder
"""
try:
st = os.stat(directory)
logger.info("Pulling as {0}:{1}...".format(st.st_uid, st.st_gid))
# order is important: after seteuid() call the effective UID isn't 0 anymore, so seteuid() will not be allowed
os.setegid(st.st_uid)
os.seteuid(st.st_gid)
repo = git.Repo(directory)
info = repo.remotes.origin.pull()[0]
if info.flags & info.ERROR:
logger.error("Pull failed: {0}".format(info.note))
return False
elif info.flags & info.REJECTED:
logger.error("Could not merge after pull: {0}".format(info.note))
return False
elif info.flags & info.HEAD_UPTODATE:
logger.info("Head is already up to date")
except PermissionError:
logger.error("Insufficient permissions to set uid/gid")
return False
finally:
logger.info("Restoring root permissions")
os.setegid(0)
os.seteuid(0)
return True
评论列表
文章目录