Qt IFW - remove log file folder
-
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 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...
-
@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...
@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]);
?
@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.
@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,
Markus -
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
-
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