mirror of
https://github.com/etlegacy/Update-Installer.git
synced 2024-11-10 14:41:50 +00:00
Fix file uninstallation and add a test
Prepend the install directory to the file path specified in the <uninstall> section of the XML file to get the path of the file to remove. If the file cannot be uninstalled because it does not exist, log a warning and continue.
This commit is contained in:
parent
dc303201fa
commit
8773a7a622
3 changed files with 22 additions and 7 deletions
|
@ -228,7 +228,15 @@ void UpdateInstaller::uninstallFiles()
|
||||||
std::vector<std::string>::const_iterator iter = m_script->filesToUninstall().begin();
|
std::vector<std::string>::const_iterator iter = m_script->filesToUninstall().begin();
|
||||||
for (;iter != m_script->filesToUninstall().end();iter++)
|
for (;iter != m_script->filesToUninstall().end();iter++)
|
||||||
{
|
{
|
||||||
FileOps::removeFile(iter->c_str());
|
std::string path = m_installDir + '/' + iter->c_str();
|
||||||
|
if (FileOps::fileExists(path.c_str()))
|
||||||
|
{
|
||||||
|
FileOps::removeFile(path.c_str());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LOG(Warn,"Unable to uninstall file " + path + " because it does not exist.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,5 +31,6 @@
|
||||||
</install>
|
</install>
|
||||||
<uninstall>
|
<uninstall>
|
||||||
<!-- TODO - List some files to uninstall here !-->
|
<!-- TODO - List some files to uninstall here !-->
|
||||||
|
<file>file-to-uninstall.txt</file>
|
||||||
</uninstall>
|
</uninstall>
|
||||||
</update>
|
</update>
|
||||||
|
|
|
@ -14,6 +14,12 @@ FileUtils.rm_rf(PACKAGE_DIR)
|
||||||
Dir.mkdir(INSTALL_DIR)
|
Dir.mkdir(INSTALL_DIR)
|
||||||
FileUtils.cp("oldapp","#{INSTALL_DIR}/app")
|
FileUtils.cp("oldapp","#{INSTALL_DIR}/app")
|
||||||
|
|
||||||
|
# Create a dummy file to uninstall
|
||||||
|
uninstall_test_file = "#{INSTALL_DIR}/file-to-uninstall.txt"
|
||||||
|
File.open(uninstall_test_file,"w") do |file|
|
||||||
|
file.puts "this file should be removed after the update"
|
||||||
|
end
|
||||||
|
|
||||||
# Create the update archive containing the new app
|
# Create the update archive containing the new app
|
||||||
Dir.mkdir(PACKAGE_DIR)
|
Dir.mkdir(PACKAGE_DIR)
|
||||||
FileUtils.cp("newapp","#{PACKAGE_DIR}/app")
|
FileUtils.cp("newapp","#{PACKAGE_DIR}/app")
|
||||||
|
@ -33,11 +39,11 @@ sleep(1)
|
||||||
|
|
||||||
# Check that the app was updated
|
# Check that the app was updated
|
||||||
output = `#{INSTALL_DIR}/app`
|
output = `#{INSTALL_DIR}/app`
|
||||||
if (output.strip == "new app starting")
|
if (output.strip != "new app starting")
|
||||||
puts "Updated app produced expected output"
|
throw "Updated app produced unexpected output: #{output}"
|
||||||
exit(0)
|
end
|
||||||
else
|
|
||||||
puts "Updated app produced unexpected output: #{output}"
|
if (File.exist?(uninstall_test_file))
|
||||||
exit(1)
|
throw "File to uninstall was not removed"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue