• Show log

    Commit

  • Hash : a00842c4
    Author : Patrick Steinhardt
    Date : 2019-06-29T09:59:14

    win32: correctly unlink symlinks to directories
    
    When deleting a symlink on Windows, then the way to delete it depends on
    whether it is a directory symlink or a file symlink. In the first case,
    we need to use `DeleteFile`, in the second `RemoveDirectory`. Right now,
    `p_unlink` will only ever try to use `DeleteFile`, though, and thus fail
    to remove directory symlinks. This mismatches how unlink(3P) is expected
    to behave, though, as it shall remove any symlink disregarding whether
    it is a file or directory symlink.
    
    In order to correctly unlink a symlink, we thus need to check what kind
    of file this is. If we were to first query file attributes of every file
    upon calling `p_unlink`, then this would penalize the common case
    though. Instead, we can try to first delete the file with `DeleteFile`
    and only if the error returned is `ERROR_ACCESS_DENIED` will we query
    file attributes and determine whether it is a directory symlink to use
    `RemoveDirectory` instead.