jpcima/smf-dsp

`make_path_absolute` can be wrong when path contains symlinks

jpcima opened this issue · 0 comments

It will be wrong to simplify a path by elimination of foo/../ kind of patterns, in case foo is a symlink.

The directory part of path may be resolved by file system API:

  • POSIX realpath
  • Windows GetFinalPathNameByHandleA (_WIN32_WINNT >= 0x0600)
  • Older Windows has no symlinks, so it's fine to use the old method.
HANDLE hDirectory = CreateFile(
    path,
    0,
    FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
    nullptr,
    OPEN_EXISTING,
    FILE_FLAG_BACKUP_SEMANTICS,
    nullptr);

GetFinalPathNameByHandleA(
    hDirectory,
    path,
    pathlen,
    VOLUME_NAME_DOS|FILE_NAME_NORMALIZED);