Qt IFW - remove log file folder
-
wrote on 31 May 2022, 17:02 last edited by MB_Inv
Hi,
I'm using Qt IFW with a component script to create a log file directory upon installation. When uninstalling, the uninstaller tries to remove this in folder, but can't as it is non-empty.
So, I tried to delete the log files by some additional operation, but the files are not deleted...
Also tried different ways (see commented out code), but to no avail.The path to the log file directory is correctly handed over to "addOperation()" (checked with console.log output when commenting out the check for the uninstaller).
// Add operations to installing/uninstalling Component.prototype.createOperations = function() { // Use standard operations as well component.createOperations(); // In case of uninstaller, clean up log file directory before removing it if (installer.isUninstaller()) { //component.addOperation("Delete", Dir.toNativeSparator(logFilePath + "/*")); // doesn't work for multiple files //component.addOperation("Execute", "cmd", "rem", "UNDOEXECUTE", ["/C", "del /q", Dir.toNativeSparator(installer.value("logFilePath") + "\\*.*")]); //component.addOperation("Execute", "cmd", "rem", "UNDOEXECUTE", "cmd", ["/C", "del /q", Dir.toNativeSparator(installer.value("logFilePath") + "\\*.*")]); //component.performOperation("Execute", "cmd", ["/C", "del /q", Dir.toNativeSparator(installer.value("logFilePath") + "\\*.*")]); component.addOperation("Execute", "erase /s /f /q", Dir.toNativeSparator(installer.value("logFilePath") + "\\*.*")); //component.addOperation("Execute", "cmd", "echo do nothing", "UNDOEXECUTE", "erase /s /f /q", Dir.toNativeSparator(installer.value("logFilePath") + "\\*.*")); //component.addOperation("UNDOEXECUTE", "erase /s /f /q", Dir.toNativeSparator(installer.value("logFilePath") + "\\*.*")); //component.addOperation("Execute", "cmd", "rem", "UNDOEXECUTE", "erase /s /f /q", Dir.toNativeSparator(installer.value("logFilePath") + "\\*.*")); //console.log("logFilePath for deletion: " + installer.value("logFilePath") + "\\*.*"); } // Create log file path dir component.addOperation("Mkdir" , logFilePath); }
By the way, "Dir.toNativeSparator()" only changes the the path separators to Win/Linux style
Any ideas what I'm doing wrong?
Any suggestions, what I could do instead? E.g, is there a way to prevent the uninstaller from trying to remove the log file folder (as you can see above, I tried with different ways e.g. using "Execute"/"UNDOEXECUTE", but that didn't work for different reasons)?Kind regards,
Markus
-
wrote on 1 Jun 2022, 11:35 last edited by
Now tried with creating a batch file from the installer (containing code for deleting the log files) which should be run by the uninstaller:
Component.prototype.createOperations = function() { // Use standard operations as well component.createOperations(); // In case of uninstaller, clean up log file directory before removing it if(installer.isUninstaller()) { installer.execute("@TargetDir@/removeLogs.bat"); //component.addElevatedOperation("Execute", "@TargetDir@/removeLogs.bat"); } //installer.execute("@TargetDir@/removeLogs.bat"); // Is never called // Create log file path dir component.addOperation("Mkdir" , logFilePath); // Create batch file for removing log files by uninstaller component.addOperation("AppendFile" , "@TargetDir@/removeLogs.bat", "del /q " + installer.value("logFilePath") + "\\*.*"); }
Creating the batch file works, the batch file itself also works (checked it after installation), however the uninstaller doesn't execute it...
Any ideas?Kind regards,
Markus
-
Now tried with creating a batch file from the installer (containing code for deleting the log files) which should be run by the uninstaller:
Component.prototype.createOperations = function() { // Use standard operations as well component.createOperations(); // In case of uninstaller, clean up log file directory before removing it if(installer.isUninstaller()) { installer.execute("@TargetDir@/removeLogs.bat"); //component.addElevatedOperation("Execute", "@TargetDir@/removeLogs.bat"); } //installer.execute("@TargetDir@/removeLogs.bat"); // Is never called // Create log file path dir component.addOperation("Mkdir" , logFilePath); // Create batch file for removing log files by uninstaller component.addOperation("AppendFile" , "@TargetDir@/removeLogs.bat", "del /q " + installer.value("logFilePath") + "\\*.*"); }
Creating the batch file works, the batch file itself also works (checked it after installation), however the uninstaller doesn't execute it...
Any ideas?Kind regards,
Markus
-
wrote on 3 Jun 2022, 08:54 last edited by MB_Inv 6 Mar 2022, 08:57
Now found a different solution by only creating the log file path folder in the installer and not removing it by the uninstaller:
// Add operations to installing/uninstalling Component.prototype.createOperations = function() { // Use standard operations as well component.createOperations(); // Installer shall create log file dir, but uninstaller should not remove it. That's why it is not added as operation if(installer.isInstaller()) { if (systemInfo.productType == "windows") { installer.execute("cmd", ["/C", "mkdir", logFilePath]); } else if (systemInfo.kernelType == "linux") { installer.execute("/bin/sh", ["-c", "mkdir -p + logFilePath"]); } } }
However, I'm having troubles getting this to work under Linux... It simply won't create the dir...
EDIT: Also not sure why the forum SW doesn't display all of my closing brackets...
-
Now found a different solution by only creating the log file path folder in the installer and not removing it by the uninstaller:
// Add operations to installing/uninstalling Component.prototype.createOperations = function() { // Use standard operations as well component.createOperations(); // Installer shall create log file dir, but uninstaller should not remove it. That's why it is not added as operation if(installer.isInstaller()) { if (systemInfo.productType == "windows") { installer.execute("cmd", ["/C", "mkdir", logFilePath]); } else if (systemInfo.kernelType == "linux") { installer.execute("/bin/sh", ["-c", "mkdir -p + logFilePath"]); } } }
However, I'm having troubles getting this to work under Linux... It simply won't create the dir...
EDIT: Also not sure why the forum SW doesn't display all of my closing brackets...
wrote on 3 Jun 2022, 09:07 last edited by JonB 6 Mar 2022, 09:08@MB_Inv said in Qt IFW - remove log file folder:
"mkdir -p + logFilePath"
logpath
is literal in the string! Don't you mean something like"mkdir -p " + logFilePath
??
Or maybeinstaller.execute("mkdir", ["-p", logFilePath]);
?
-
wrote on 3 Jun 2022, 09:21 last edited by
@JonB
I tried (at least) the following variants:- component.addElevatedOperation("Execute", "@TargetDir@/removeLogs.bat");
- component.addOperation("Execute", "cmd", "-c", "echo", "do nothing", "UNDOEXECUTE", "@TargetDir@/removeLogs.bat");
- component.addOperation("Execute", "cmd", ["/C", "@TargetDir@\removeLogs.bat"]);
- component.addOperation("Execute", "cmd", ["/C", "C:_data\removeLogs.bat"]);
None of which worked...
-
@JonB
I tried (at least) the following variants:- component.addElevatedOperation("Execute", "@TargetDir@/removeLogs.bat");
- component.addOperation("Execute", "cmd", "-c", "echo", "do nothing", "UNDOEXECUTE", "@TargetDir@/removeLogs.bat");
- component.addOperation("Execute", "cmd", ["/C", "@TargetDir@\removeLogs.bat"]);
- component.addOperation("Execute", "cmd", ["/C", "C:_data\removeLogs.bat"]);
None of which worked...
wrote on 3 Jun 2022, 09:36 last edited by@MB_Inv
To determine whether yourremoveLogs.bat
is not doing what you think it should versus not being executed, put something like:echo "Executed" >> C:\Temp\tempfile
as its first line (obviously adjust the path for the temp file for your system). See whether the file exists after the operation has been performed.
-
@MB_Inv said in Qt IFW - remove log file folder:
"mkdir -p + logFilePath"
logpath
is literal in the string! Don't you mean something like"mkdir -p " + logFilePath
??
Or maybeinstaller.execute("mkdir", ["-p", logFilePath]);
?
wrote on 3 Jun 2022, 09:41 last edited by@JonB said in Qt IFW - remove log file folder:
@MB_Inv said in Qt IFW - remove log file folder:
"mkdir -p + logFilePath"
logpath
is literal in the string! Don't you mean something like"mkdir -p " + logFilePath
??
Or maybeinstaller.execute("mkdir", ["-p", logFilePath]);
?
Yes, you're right. Strange that I overlooked this...
Using
installer.execute("/bin/sh", ["-c", "mkdir -p \"" + logFilePath + "\""]);
it indeed works...
Thanks for the hint :-)
Kind regards,
Markus
-
@MB_Inv
To determine whether yourremoveLogs.bat
is not doing what you think it should versus not being executed, put something like:echo "Executed" >> C:\Temp\tempfile
as its first line (obviously adjust the path for the temp file for your system). See whether the file exists after the operation has been performed.
wrote on 3 Jun 2022, 10:59 last edited by@JonB said in Qt IFW - remove log file folder:
@MB_Inv
To determine whether yourremoveLogs.bat
is not doing what you think it should versus not being executed, put something like:echo "Executed" >> C:\Temp\tempfile
as its first line (obviously adjust the path for the temp file for your system). See whether the file exists after the operation has been performed.
Thanks for this hint, too!
However, I tried running the batch file manually which indeed removed what it should do (remove the log files).
But, of course, a good idea to make further tests more convenient...Kind regards,
Markus -
@JonB said in Qt IFW - remove log file folder:
@MB_Inv
To determine whether yourremoveLogs.bat
is not doing what you think it should versus not being executed, put something like:echo "Executed" >> C:\Temp\tempfile
as its first line (obviously adjust the path for the temp file for your system). See whether the file exists after the operation has been performed.
Thanks for this hint, too!
However, I tried running the batch file manually which indeed removed what it should do (remove the log files).
But, of course, a good idea to make further tests more convenient...Kind regards,
Markuswrote on 3 Jun 2022, 11:14 last edited by@MB_Inv
You have not stated whether from this change you have determined whether the.bat
is actually being run versus not doing what you expect?
If it is being run but not doing what you want, you have never shown the content of yourremoveLogs.bat
? -
wrote on 8 Jun 2022, 06:29 last edited by
Sorry, I must have overlooked that I didn't provide the batch file contents...
The batch file was created using the following code in Component.prototype.createOperations = function()// Create batch file for removing log files by uninstaller component.addOperation("AppendFile" , "@TargetDir@/removeLogs.bat", "del /q " + installer.value("logFilePath") + "\\*.*");
So, it simply contains e.g.
del /q C:\_data\test\logs\*.*
Calling this file (the one created by the installer) manually (by double-clicking on it in the explorer), it did indeed delete the files in the logs dir. So I concluded that it simply wasn't called by the installer.
But will check, again, with your hint.
Kind regards,
Markus
-
wrote on 8 Jun 2022, 06:51 last edited by
Checked again with the "echo" line in the batch file.
So, I used the following code (so, the log files should be actually removed several times):
// Add operations to installing/uninstalling Component.prototype.createOperations = function() { // Use standard operations as well component.createOperations(); // In case of uninstaller, clean up log file directory before removing it if(installer.isUninstaller()) { if(systemInfo.productType == "windows") { component.addOperation("Execute", "erase /s /f /q", Dir.toNativeSparator(installer.value("logFilePath") + "\\*.*")); } component.addOperation("Execute", "cmd", ["/C", "@TargetDir@\removeLogs.bat"]); } if(installer.isInstaller()) { installer.execute("cmd", ["/C", "mkdir", logFilePath]); } if(installer.isUninstaller()) { installer.execute("cmd", ["/C", "@TargetDir@\removeLogs.bat"]); } // Create batch file for removing log files by uninstaller component.addOperation("AppendFile" , "@TargetDir@/removeLogs.bat", "echo \"Executed\" >> C:\\_data\\test.txt\ndel /q " + installer.value("logFilePath") + "\\*.*"); }
The batch file was correctly created in the target dir, containing
echo "Executed" >> C:\_data\test.txt del /q C:\_data\test\logs\*.*
However, the files were not deleted by the uninstaller, nor was C:_data\test.txt written.
Before uninstallation, I copied the batch file also to C:_data. After uninstallation, I simply executed the batch file by double-clicking on it from the Win explorer and both the files were successfully deleted as well as C:_data\test.txt written.
Did I maybe simply overlook something?
Or maybe this simply doesn't work in the createOperations function?Kind regards,
Markus
1/12