summaryrefslogtreecommitdiffstats
path: root/source/core/slang-io.cpp
diff options
context:
space:
mode:
authorEllie Hermaszewska <ellieh@nvidia.com>2023-04-14 00:00:56 +0800
committerGitHub <noreply@github.com>2023-04-14 00:00:56 +0800
commit59a603593f06ca2935a376b17a91ec42657f1ef8 (patch)
tree16147c6952e526c536597c816bf7ccc4f40f94cd /source/core/slang-io.cpp
parentc7e5601bb67d2a5ebadb7f84c6968b5912e7566d (diff)
Set the executable bit on Executable artifact files (#2796)
* Set the executable bit on Executable artifact files * Don't zero out other permission bits in makeExecutable
Diffstat (limited to 'source/core/slang-io.cpp')
-rw-r--r--source/core/slang-io.cpp18
1 files changed, 16 insertions, 2 deletions
diff --git a/source/core/slang-io.cpp b/source/core/slang-io.cpp
index 6f97ef45d..5c57a4b3a 100644
--- a/source/core/slang-io.cpp
+++ b/source/core/slang-io.cpp
@@ -154,8 +154,22 @@ namespace Slang
// As long as file extension is executable, it can be executed
return SLANG_OK;
#else
- const int ret = ::chmod(fileName.getBuffer(), S_IXUSR);
- return (ret == 0) ? SLANG_OK : SLANG_FAIL;
+ struct stat st;
+ if(::stat(fileName.getBuffer(), &st) != 0)
+ {
+ return SLANG_FAIL;
+ }
+ if(st.st_mode & S_IXUSR)
+ {
+ return SLANG_OK;
+ }
+ // It would probably be slightly neater to set all executable bits
+ // aside from those in umask..
+ if(::chmod(fileName.getBuffer(), st.st_mode & 07777 | S_IXUSR) != 0)
+ {
+ return SLANG_FAIL;
+ }
+ return SLANG_OK;
#endif
}