diff --git a/daemon/util/FileSystem.cpp b/daemon/util/FileSystem.cpp index eb2f14961..b315617c4 100644 --- a/daemon/util/FileSystem.cpp +++ b/daemon/util/FileSystem.cpp @@ -961,15 +961,19 @@ void FileSystem::FixExecPermission(const char* filename) void FileSystem::SetFilePermissionsWithUmask(const char* filename, mode_t umask) { - mode_t permissions = buffer.st_mode & ~umask; - info("%s %o %s %s", "Setting permissons ", permissions, "on", filename); - if (!chmod(filename, permissions)) - { - info("%s", "Success"); - } - else + struct stat buffer; + if (!stat(filename, &buffer)) { - error("%s", "Failure"); + mode_t permissions = buffer.st_mode & ~umask; + info("%s %o %s %s", "Setting permissons ", permissions, "on", filename); + if (!chmod(filename, permissions)) + { + info("%s", "Success"); + } + else + { + error("%s", "Failure"); + } } } #endif