xmake-io / xmake

🔥 A cross-platform build utility based on Lua
https://xmake.io
Apache License 2.0
9.74k stars 767 forks source link

Dangling symlinks and os.exists() #5328

Closed SirNate0 closed 1 month ago

SirNate0 commented 1 month ago

Xmake Version

xmake v2.9.3+dev.1556ddbf9

Operating System Version and Architecture

Kubuntu 22.04

Describe Bug

os.exists() returns false when the file is a symlink that points to a file that does not exist. However, because the symlink itself exists, os.ln() will fail to create a symlink in it's place.

Expected Behavior

Current behavior is probably acceptable, but a note should be added to the documentation about this subtlety. os.islink() can be used to see that it is actually a symlink, but either a note to the documentation to clarify, or an argument to the function itself would be helpful.

Project Configuration

Just add this to a target and build (it will delete the file link)

    before_build(function (target)
        os.tryrm('link')
        os.ln('to_nothing','link')
        print(os.exists('link'))
        print(os.readlink('link'))
        print(os.islink('link'))
        print(os.islink('nonexistent'))
        os.ln('link','xmake.lua')
    end)

Additional Information and Error Logs

N/A

waruqi commented 1 month ago

you should use os.islink instead of os.exists, and you can open a pr to improve docs.