wget2
wget2 copied to clipboard
Directory prefix provided with -P/--directory-prefix is not normalized correctly
If a directory prefix is provided its path components are not normalized correctly, which in turn causes the function mkdir_path to fail. Examples:
-P ./downloads works
-P ../downloads works
-P ../../downloads does not work (Internal error: Unexpected relative path: '../..')
-P ./../downloads does not work (Internal error: Unexpected relative path: './..')
-P /home/user/downloads/../downloads does not work (Internal error: Unexpected relative path: '/home/user/downloads/..')
I would not expect, nor actually want, mkdir_path to create the path components of the directory prefix (only the patch components from a recursively downloaded directory tree).
IMHO, wget2 should use realpath (or equivalent) to obtain the canonicalized absolute path name, then check if the path exists, and if so, use it subsequently. If the path does not exist or is actually a file then it should abort.