Skip to content

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

Open
mercury233 wants to merge 2 commits into
premake:masterfrom
mercury233:patch-isdir
Open

fix os.isdir() and os.mkdir()#2759
mercury233 wants to merge 2 commits 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.
  • Simplified the implementation of os.isdir.
  • Added tests for os.mkdir. On FreeBSD CI, the workspace is mounted through SSHFS, which does not reliably support this symlink topology. The test therefore uses local temporary storage to exercise the actual os.mkdir behavior without interference from the CI filesystem.

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

Copy link
Copy Markdown
Contributor Author

The current test needs to be run outside the “sandbox” in order to pass, due to the reasons mentioned above.

  • Run the test outside the sandbox.
  • Skip this test on FreeBSD, or skip it only in the FreeBSD CI via an environment variable.
  • Abandon this test completely.

I am not sure which option would be the most appropriate.

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
--

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.

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