Make sync_url work relative to cwd like sane programs

This commit is contained in:
Christophe 2020-12-02 16:50:30 +01:00
parent 9cbea5fe06
commit ecdbca8fb6

View File

@ -35,19 +35,15 @@ def main() -> None:
cookie_jar.load_cookies() cookie_jar.load_cookies()
if args.folder is not None: folder = args.folder
folder = args.folder if args.folder is None:
# Initialize pferd at the *parent of the passed folder*
# This is needed so Pferd's internal protections against escaping the working directory
# do not trigger (e.g. if somebody names a file in ILIAS '../../bad thing.txt')
pferd = Pferd(Path(Path(__file__).parent, folder).parent, test_run=args.test_run)
else:
# fetch course name from ilias
folder = crawler.find_element_name(args.url) folder = crawler.find_element_name(args.url)
cookie_jar.save_cookies() cookie_jar.save_cookies()
# Initialize pferd at the location of the script # files may not escape the pferd_root with relative paths
pferd = Pferd(Path(__file__).parent, test_run=args.test_run) # note: Path(Path.cwd, Path(folder)) == Path(folder) if it is an absolute path
pferd_root = Path(Path.cwd(), Path(folder)).parent
pferd = Pferd(pferd_root, test_run=args.test_run)
def dir_filter(_: Path, element: IliasElementType) -> bool: def dir_filter(_: Path, element: IliasElementType) -> bool:
if args.no_videos: if args.no_videos: