mirror of
https://github.com/etlegacy/Update-Installer.git
synced 2025-02-17 00:41:11 +00:00
Convert Qt permission flags (from QFile::Permissions) to Unix mode_t flags.
This fixes the permissions set on files by the updater.
This commit is contained in:
parent
2f7a131cb4
commit
c1a5cce3da
4 changed files with 56 additions and 7 deletions
|
@ -60,14 +60,13 @@ bool FileOps::fileExists(const char* path) throw (IOException)
|
|||
#endif
|
||||
}
|
||||
|
||||
void FileOps::setPermissions(const char* path, int permissions) throw (IOException)
|
||||
void FileOps::setQtPermissions(const char* path, int qtPermissions) throw (IOException)
|
||||
{
|
||||
#ifdef PLATFORM_UNIX
|
||||
// TODO - Convert permissions correctly
|
||||
int mode = permissions;
|
||||
int mode = toUnixPermissions(qtPermissions);
|
||||
if (chmod(path,mode) != 0)
|
||||
{
|
||||
throw IOException("Failed to set permissions on " + std::string(path) + " to " + intToStr(permissions));
|
||||
throw IOException("Failed to set permissions on " + std::string(path) + " to " + intToStr(qtPermissions));
|
||||
}
|
||||
#else
|
||||
throw IOException("not implemented");
|
||||
|
@ -265,3 +264,27 @@ std::string FileOps::canonicalPath(const char* path)
|
|||
#endif
|
||||
}
|
||||
|
||||
template <class InFlags, class OutFlags>
|
||||
void addFlag(InFlags inFlags, int testBit, OutFlags& outFlags, int setBit)
|
||||
{
|
||||
if (inFlags & testBit)
|
||||
{
|
||||
outFlags |= setBit;
|
||||
}
|
||||
}
|
||||
|
||||
int FileOps::toUnixPermissions(int qtPermissions)
|
||||
{
|
||||
mode_t result = 0;
|
||||
addFlag(qtPermissions,ReadUser,result,S_IRUSR);
|
||||
addFlag(qtPermissions,WriteUser,result,S_IWUSR);
|
||||
addFlag(qtPermissions,ExecUser,result,S_IXUSR);
|
||||
addFlag(qtPermissions,ReadGroup,result,S_IRGRP);
|
||||
addFlag(qtPermissions,WriteGroup,result,S_IWGRP);
|
||||
addFlag(qtPermissions,ExecGroup,result,S_IXGRP);
|
||||
addFlag(qtPermissions,ReadOther,result,S_IROTH);
|
||||
addFlag(qtPermissions,WriteOther,result,S_IWOTH);
|
||||
addFlag(qtPermissions,ExecOther,result,S_IXOTH);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -25,8 +25,24 @@ class FileOps
|
|||
int m_errno;
|
||||
};
|
||||
|
||||
enum QtFilePermission
|
||||
{
|
||||
ReadOwner = 0x4000,
|
||||
WriteOwner = 0x2000,
|
||||
ExecOwner = 0x1000,
|
||||
ReadUser = 0x0400,
|
||||
WriteUser = 0x0200,
|
||||
ExecUser = 0x0100,
|
||||
ReadGroup = 0x0040,
|
||||
WriteGroup = 0x0020,
|
||||
ExecGroup = 0x0010,
|
||||
ReadOther = 0x0004,
|
||||
WriteOther = 0x0002,
|
||||
ExecOther = 0x0001
|
||||
};
|
||||
|
||||
static void setQtPermissions(const char* path, int permissions) throw (IOException);
|
||||
static bool fileExists(const char* path) throw (IOException);
|
||||
static void setPermissions(const char* path, int permissions) throw (IOException);
|
||||
static void moveFile(const char* src, const char* dest) throw (IOException);
|
||||
static void removeFile(const char* src) throw (IOException);
|
||||
static void extractFromZip(const char* zipFile, const char* src, const char* dest) throw (IOException);
|
||||
|
@ -38,5 +54,8 @@ class FileOps
|
|||
static std::string dirname(const char* path);
|
||||
static void rmdirRecursive(const char* dir) throw (IOException);
|
||||
static std::string canonicalPath(const char* path);
|
||||
|
||||
private:
|
||||
static int toUnixPermissions(int qtPermissions);
|
||||
};
|
||||
|
||||
|
|
|
@ -199,7 +199,7 @@ void UpdateInstaller::installFile(const UpdateScriptFile& file)
|
|||
FileOps::extractFromZip(packageFile.c_str(),file.path.c_str(),destPath.c_str());
|
||||
|
||||
// set the permissions on the newly extracted file
|
||||
FileOps::setPermissions(destPath.c_str(),file.permissions);
|
||||
FileOps::setQtPermissions(destPath.c_str(),file.permissions);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -38,11 +38,18 @@ system("#{PACKAGE_DIR}/updater --install-dir #{INSTALL_DIR} --package-dir #{PACK
|
|||
sleep(1)
|
||||
|
||||
# Check that the app was updated
|
||||
output = `#{INSTALL_DIR}/app`
|
||||
app_path = "#{INSTALL_DIR}/app"
|
||||
output = `#{app_path}`
|
||||
if (output.strip != "new app starting")
|
||||
throw "Updated app produced unexpected output: #{output}"
|
||||
end
|
||||
|
||||
# Check that the permissions were correctly set on the installed app
|
||||
mode = File.stat(app_path).mode.to_s(8)
|
||||
if (mode != "100755")
|
||||
throw "Updated app has incorrect permissions: #{mode}"
|
||||
end
|
||||
|
||||
if (File.exist?(uninstall_test_file))
|
||||
throw "File to uninstall was not removed"
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue