From 59a603593f06ca2935a376b17a91ec42657f1ef8 Mon Sep 17 00:00:00 2001 From: Ellie Hermaszewska Date: Fri, 14 Apr 2023 00:00:56 +0800 Subject: 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 --- source/core/slang-io.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'source/core/slang-io.cpp') 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 } -- cgit v1.2.3