Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Installation and Deployment
  4. Qt IFW - remove log file folder
Forum Updated to NodeBB v4.3 + New Features

Qt IFW - remove log file folder

Scheduled Pinned Locked Moved Unsolved Installation and Deployment
12 Posts 2 Posters 1.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MB_Inv
    wrote on 31 May 2022, 17:02 last edited by MB_Inv
    #1

    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

    1 Reply Last reply
    0
    • M Offline
      M Offline
      MB_Inv
      wrote on 1 Jun 2022, 11:35 last edited by
      #2

      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

      J 1 Reply Last reply 1 Jun 2022, 12:42
      0
      • M MB_Inv
        1 Jun 2022, 11:35

        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

        J Offline
        J Offline
        JonB
        wrote on 1 Jun 2022, 12:42 last edited by
        #3

        @MB_Inv
        For a .bat file did you try cmd /c file.bat to execute it?

        M 1 Reply Last reply 3 Jun 2022, 09:21
        0
        • M Offline
          M Offline
          MB_Inv
          wrote on 3 Jun 2022, 08:54 last edited by MB_Inv 6 Mar 2022, 08:57
          #4

          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...

          J 1 Reply Last reply 3 Jun 2022, 09:07
          0
          • M MB_Inv
            3 Jun 2022, 08:54

            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...

            J Offline
            J Offline
            JonB
            wrote on 3 Jun 2022, 09:07 last edited by JonB 6 Mar 2022, 09:08
            #5

            @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 maybe

            installer.execute("mkdir", ["-p", logFilePath]);
            

            ?

            M 1 Reply Last reply 3 Jun 2022, 09:41
            1
            • J JonB
              1 Jun 2022, 12:42

              @MB_Inv
              For a .bat file did you try cmd /c file.bat to execute it?

              M Offline
              M Offline
              MB_Inv
              wrote on 3 Jun 2022, 09:21 last edited by
              #6

              @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...

              J 1 Reply Last reply 3 Jun 2022, 09:36
              0
              • M MB_Inv
                3 Jun 2022, 09:21

                @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...

                J Offline
                J Offline
                JonB
                wrote on 3 Jun 2022, 09:36 last edited by
                #7

                @MB_Inv
                To determine whether your removeLogs.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.

                M 1 Reply Last reply 3 Jun 2022, 10:59
                0
                • J JonB
                  3 Jun 2022, 09:07

                  @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 maybe

                  installer.execute("mkdir", ["-p", logFilePath]);
                  

                  ?

                  M Offline
                  M Offline
                  MB_Inv
                  wrote on 3 Jun 2022, 09:41 last edited by
                  #8

                  @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 maybe

                  installer.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

                  1 Reply Last reply
                  2
                  • J JonB
                    3 Jun 2022, 09:36

                    @MB_Inv
                    To determine whether your removeLogs.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.

                    M Offline
                    M Offline
                    MB_Inv
                    wrote on 3 Jun 2022, 10:59 last edited by
                    #9

                    @JonB said in Qt IFW - remove log file folder:

                    @MB_Inv
                    To determine whether your removeLogs.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

                    J 1 Reply Last reply 3 Jun 2022, 11:14
                    0
                    • M MB_Inv
                      3 Jun 2022, 10:59

                      @JonB said in Qt IFW - remove log file folder:

                      @MB_Inv
                      To determine whether your removeLogs.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

                      J Offline
                      J Offline
                      JonB
                      wrote on 3 Jun 2022, 11:14 last edited by
                      #10

                      @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 your removeLogs.bat?

                      1 Reply Last reply
                      0
                      • M Offline
                        M Offline
                        MB_Inv
                        wrote on 8 Jun 2022, 06:29 last edited by
                        #11

                        @JonB

                        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

                        1 Reply Last reply
                        0
                        • M Offline
                          M Offline
                          MB_Inv
                          wrote on 8 Jun 2022, 06:51 last edited by
                          #12

                          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 Reply Last reply
                          0

                          1/12

                          31 May 2022, 17:02

                          • Login

                          • Login or register to search.
                          1 out of 12
                          • First post
                            1/12
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • Users
                          • Groups
                          • Search
                          • Get Qt Extensions
                          • Unsolved