diff --git a/modules/juce_core/files/juce_File.cpp b/modules/juce_core/files/juce_File.cpp index d5c520a098..19d724b0ad 100644 --- a/modules/juce_core/files/juce_File.cpp +++ b/modules/juce_core/files/juce_File.cpp @@ -219,6 +219,11 @@ bool File::setReadOnly (const bool shouldBeReadOnly, return setFileReadOnlyInternal (shouldBeReadOnly) && worked; } +bool File::setExecutePermission (bool shouldBeExecutable) const +{ + return setFileExecutableInternal (shouldBeExecutable); +} + bool File::deleteRecursively() const { bool worked = true; diff --git a/modules/juce_core/files/juce_File.h b/modules/juce_core/files/juce_File.h index 57d970fff0..522559aace 100644 --- a/modules/juce_core/files/juce_File.h +++ b/modules/juce_core/files/juce_File.h @@ -348,6 +348,13 @@ public: bool setReadOnly (bool shouldBeReadOnly, bool applyRecursively = false) const; + /** Changes the execute-permissions of a file. + + @param shouldBeExecutable whether to add or remove execute-permission + @returns true if it manages to change the file's permissions. + */ + bool setExecutePermission (bool shouldBeExecutable) const; + /** Returns true if this file is a hidden or system file. The criteria for deciding whether a file is hidden are platform-dependent. */ @@ -968,6 +975,7 @@ private: bool setFileTimesInternal (int64 m, int64 a, int64 c) const; void getFileTimesInternal (int64& m, int64& a, int64& c) const; bool setFileReadOnlyInternal (bool) const; + bool setFileExecutableInternal (bool) const; }; #endif // JUCE_FILE_H_INCLUDED diff --git a/modules/juce_core/native/juce_posix_SharedCode.h b/modules/juce_core/native/juce_posix_SharedCode.h index 91785d6ad7..c94d3a6358 100644 --- a/modules/juce_core/native/juce_posix_SharedCode.h +++ b/modules/juce_core/native/juce_posix_SharedCode.h @@ -304,23 +304,33 @@ bool File::hasWriteAccess() const return false; } -bool File::setFileReadOnlyInternal (const bool shouldBeReadOnly) const +static bool setFileModeFlags (const String& fullPath, mode_t flags, bool shouldSet) noexcept { juce_statStruct info; if (! juce_stat (fullPath, info)) return false; - info.st_mode &= 0777; // Just permissions + info.st_mode &= 0777; - if (shouldBeReadOnly) - info.st_mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH); + if (shouldSet) + info.st_mode |= flags; else - // Give everybody write permission? - info.st_mode |= S_IWUSR | S_IWGRP | S_IWOTH; + info.st_mode &= ~flags; return chmod (fullPath.toUTF8(), info.st_mode) == 0; } +bool File::setFileReadOnlyInternal (bool shouldBeReadOnly) const +{ + // Hmm.. should we give global write permission or just the current user? + return setFileModeFlags (fullPath, S_IWUSR | S_IWGRP | S_IWOTH, ! shouldBeReadOnly); +} + +bool File::setFileExecutableInternal (bool shouldBeExecutable) const +{ + return setFileModeFlags (fullPath, S_IXUSR | S_IXGRP | S_IXOTH, shouldBeExecutable); +} + void File::getFileTimesInternal (int64& modificationTime, int64& accessTime, int64& creationTime) const { modificationTime = 0; @@ -328,11 +338,12 @@ void File::getFileTimesInternal (int64& modificationTime, int64& accessTime, int creationTime = 0; juce_statStruct info; + if (juce_stat (fullPath, info)) { - modificationTime = (int64) info.st_mtime * 1000; - accessTime = (int64) info.st_atime * 1000; - creationTime = (int64) info.st_ctime * 1000; + modificationTime = (int64) info.st_mtime * 1000; + accessTime = (int64) info.st_atime * 1000; + creationTime = (int64) info.st_ctime * 1000; } } diff --git a/modules/juce_core/native/juce_win32_Files.cpp b/modules/juce_core/native/juce_win32_Files.cpp index a77aa5aaca..260ed12b64 100644 --- a/modules/juce_core/native/juce_win32_Files.cpp +++ b/modules/juce_core/native/juce_win32_Files.cpp @@ -163,6 +163,12 @@ bool File::setFileReadOnlyInternal (const bool shouldBeReadOnly) const || SetFileAttributes (fullPath.toWideCharPointer(), newAtts) != FALSE; } +bool File::setFileExecutableInternal (bool shouldBeExecutable) +{ + // XXX is this possible? + return false; +} + bool File::isHidden() const { return (WindowsFileHelpers::getAtts (fullPath) & FILE_ATTRIBUTE_HIDDEN) != 0;