joinpath function
This commit is contained in:
parent
3a4a30034e
commit
3354da7024
1 changed files with 16 additions and 0 deletions
16
koji/util.py
16
koji/util.py
|
|
@ -504,6 +504,22 @@ def move_and_symlink(src, dst, relative=True, create_dir=False):
|
|||
os.symlink(dst, src)
|
||||
|
||||
|
||||
|
||||
def joinpath(path, *paths):
|
||||
"""A wrapper around os.path.join that limits directory traversal"""
|
||||
|
||||
# note that the first path is left alone
|
||||
|
||||
newpaths = []
|
||||
for _p in paths:
|
||||
p = os.path.normpath(_p)
|
||||
if p == '..' or p.startswith('../') or p.startswith('/'):
|
||||
raise ValueError('Invalid path segment: %s' % _p)
|
||||
newpaths.append(p)
|
||||
|
||||
return os.path.join(path, *newpaths)
|
||||
|
||||
|
||||
def eventFromOpts(session, opts):
|
||||
"""Determine event id from standard cli options
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue