From 8773a7a62256b9ae950604fa60426708eaa3568f Mon Sep 17 00:00:00 2001 From: Robert Knight Date: Sun, 21 Aug 2011 23:41:57 +0100 Subject: [PATCH] Fix file uninstallation and add a test Prepend the install directory to the file path specified in the 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. --- src/UpdateInstaller.cpp | 10 +++++++++- src/tests/file_list.xml | 1 + src/tests/test-update.rb | 18 ++++++++++++------ 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/UpdateInstaller.cpp b/src/UpdateInstaller.cpp index e42f554..a6bc237 100644 --- a/src/UpdateInstaller.cpp +++ b/src/UpdateInstaller.cpp @@ -228,7 +228,15 @@ void UpdateInstaller::uninstallFiles() std::vector::const_iterator iter = m_script->filesToUninstall().begin(); 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."); + } } } diff --git a/src/tests/file_list.xml b/src/tests/file_list.xml index ef8391a..97e57b3 100644 --- a/src/tests/file_list.xml +++ b/src/tests/file_list.xml @@ -31,5 +31,6 @@ + file-to-uninstall.txt diff --git a/src/tests/test-update.rb b/src/tests/test-update.rb index 3702289..673652b 100755 --- a/src/tests/test-update.rb +++ b/src/tests/test-update.rb @@ -14,6 +14,12 @@ FileUtils.rm_rf(PACKAGE_DIR) Dir.mkdir(INSTALL_DIR) 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 Dir.mkdir(PACKAGE_DIR) FileUtils.cp("newapp","#{PACKAGE_DIR}/app") @@ -33,11 +39,11 @@ sleep(1) # Check that the app was updated output = `#{INSTALL_DIR}/app` -if (output.strip == "new app starting") - puts "Updated app produced expected output" - exit(0) -else - puts "Updated app produced unexpected output: #{output}" - exit(1) +if (output.strip != "new app starting") + throw "Updated app produced unexpected output: #{output}" +end + +if (File.exist?(uninstall_test_file)) + throw "File to uninstall was not removed" end