RKrahl / archive-tools

Tools for managing archives
Apache License 2.0
1 stars 2 forks source link

archive-tool create throws an error when trying to explicitly add a symlink #37

Closed RKrahl closed 5 years ago

RKrahl commented 5 years ago

When trying to create an archive adding a symbolic link as a file argument, archive-tool throws an error "invalid path ...: must be normalized":

$ ls -lad base/data base/s.dat
drwxr-x--- 1 rolf users 14  6. Aug 15:04 base/data
lrwxrwxrwx 1 rolf users 12  6. Aug 15:04 base/s.dat -> data/rnd.dat
$ archive-tool.py create archive.tar base/data base/s.dat 
archive-tool.py create: error: invalid path base/s.dat: must be normalized
RKrahl commented 5 years ago

The culprit is the _is_normalized() helper function in module archive.archive:

def _is_normalized(p):
    """Check if the path is normalized.
    """
    p = Path.cwd() / p
    if p.resolve() == p:
        return True
    if p.is_symlink():
        return p.resolve().parent == p.parent
    else:
        return False

The idea was to enforce that all paths should be below the base directory and exclude paths like base/../../../etc/passwd. The condition for symlinks should be return p.parent.resolve() == p.parent instead.