rmdir/del change read-only state of src hard links

Alec Miller 0 Reputation points

We have assets backed by Perforce that we need to duplicate into another folder hiearchy. To do this we use mklink /H to create hard links to the source files. Our makefile deletes this folder hierarchy every build, and relinks the files that are present. But I'm seeing that rmdir (or del) both change the read-only state of the source files when deleting the hard links. This then messes with Perforce's read-only tracking state, and it can't clobber the files as a result.

How is it that rmdir/del can't just delete the hardlink without modifying the attribute state?

This is on Win10.

Version 10.0.19045 Build 19045

Here's an easy repro. Create src/test.txt file and set it read-only. Then run this script 2x. Note that the rmdir changes the src/test.txt read-only state to false. That should not happen.


rmdir /S /Q dst

mkdir dst

mklink test.txt ..\src.test\text.txt

Also why does mklink symlink creation fail for the same dual workingDir case that hard links only work for. This whole realtive to link also breaks any code that was using ln -s for posix. I don't have a path relative to the link, I just have the two folders of where the files are.

rem this succeeds, but has the read-only bug
rem mklink /H dst\test.txt src\test.txt

rem this succeeds, but creates an invalid link
rem mklink dst\test.txt src\test.txt

rem this works, but means a massive change to code using ln -s or mklink /H
rem mklink dst\test.txt ..\src\test.txt

Windows 10
Windows 10
A Microsoft operating system that runs on personal computers and tablets.
8,830 questions
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
1,294 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Alec Miller 0 Reputation points

    Sorry typo in the script above.

    rmdir /S /Q dst
    mkdir dst

    mklink dst\test.txt ..\src\text.txt

  2. Alec Miller 0 Reputation points

    Also since this is rmdir/del recursively wiping out the source read-only state, that makes it hard since we'd have to preserve the read-only state of all files prior to the call, and then restore the state. Some content is checked out and not read-only. This is a pretty horrible bug that seems to have been in rmdir/del for years.

  3. Alec Miller 0 Reputation points

    This is even worse.

    1. Create a file test.txt and make it read-only
    2. Create a folder test
    3. mklink /H test\test.txt test.txt
    4. delete test folder from Explorer
    5. test.txt is still read-only
    6. Empty recycle bin
    7. test.txt is no longer read-only

    So this bug exists in Explorer as well. I have a custom tool to search and delete a hardlink and restore read-only state to one of the other hardlinks. Unfortunately, this also finds any hardlinks in the recycle bin.

    So this is something Microsoft has to fix. This totally breaks use of read-only state, and the way Perforce identifies changed files.

    0 comments No comments