Skip to content

fix os.isdir() and os.mkdir() - #2759

Open
mercury233 wants to merge 1 commit into
premake:masterfrom
mercury233:patch-isdir
Open

fix os.isdir() and os.mkdir()#2759
mercury233 wants to merge 1 commit into
premake:masterfrom
mercury233:patch-isdir

Conversation

@mercury233

@mercury233 mercury233 commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

  • On MinGW, _wstat does not fully recognize reparse points (symbolic links); GetFileAttributesW needs to be used instead.
  • Fixed an issue where os.mkdir incorrectly returned success when the target already existed and was a file, added the test.
  • Simplified the implementation of os.isdir.

How does this PR change Premake's behavior?

In the edge case where the target of mkdir already exists and is a file, the operation may now terminate earlier.

Anything else we should know?

Did you check all the boxes?

  • Focus on a single fix or feature; remove any unrelated formatting or code changes
  • Add unit tests showing fix or feature works; all tests pass
  • Mention any related issues (put closes #XXXX in comment to auto-close issue when PR is merged)
  • Follow our coding conventions
  • Minimize the number of commits
  • Align documentation to your changes

You can now support Premake on our OpenCollective. Your contributions help us spend more time responding to requests like these!

@mercury233

This comment was marked as outdated.

Comment thread tests/base/test_os.lua Outdated
local ok, err = os.mkdir("folder/ok.lua")
test.isnil(ok)
test.isequal("string", type(err))
test.istrue(os.isfile("folder/ok.lua"))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would move test.istrue(os.isfile("folder/ok.lua")) at the beginning. It is the prerequire for the failure of os.mkdir

Comment thread tests/base/test_os.lua Outdated
--

function suite.mkdir_ReturnsTrue_OnExistingDirectoryLink()
-- BSD CI mounts the workspace through SSHFS, so keep topology tests on local storage.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What was the actual problem?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/premake/premake-core/actions/runs/30967252835/job/92183785538
after os.linkdir("folder/subfolder", "folder/subfolder2"), os.mkdir("folder/subfolder2") fail.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did it fail?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m not sure. I can only guess that it has something to do with SSHFS.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likely related to issues that I started addressing with #2749, if I had to guess. Our BSD VM seems to be breaking quite a bit of code that works elsewhere. Not sure if it's with the VM set up or if it's BSD itself.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment reads as if it's obvious why you'd use local storage when using BSD and SSHFS, but then you're not sure why it doesn't work. We might just be calling the wrong functions on BSD? It would be nice to have more investigation into the issue so that we can clearly state why this test doesn't work with that configuration.

@mercury233 mercury233 Aug 20, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment reads as if it's obvious why you'd use local storage when using BSD and SSHFS, but then you're not sure why it doesn't work. We might just be calling the wrong functions on BSD? It would be nice to have more investigation into the issue so that we can clearly state why this test doesn't work with that configuration.

Sorry, I'm not interested about BSD. So I've just removed the test.

@nickclark2016

Copy link
Copy Markdown
Member

I want to follow up on this. Currently, our CI jobs are passing. Is this a gap in our current testing?

@mercury233

mercury233 commented Aug 20, 2026

Copy link
Copy Markdown
Contributor Author

I want to follow up on this. Currently, our CI jobs are passing. Is this a gap in our current testing?

The main issue is that previously, os.mkdir would return success when the target already existed as a file. Fixing this requires reliably checking the attributes of the target, which introduced symlink detection and, in turn, caused an issue in the FreeBSD CI.

The current test works around this issue, but it introduces file operations outside the sandbox (in a temporary directory). I've dropped the newly added test, I think this probably wouldn’t cause any issues in practice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants