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 MB_Inv

    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

    JonBJ Offline
    JonBJ Offline
    JonB
    wrote on 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
    0
    • M Offline
      M Offline
      MB_Inv
      wrote on last edited by MB_Inv
      #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...

      JonBJ 1 Reply Last reply
      0
      • M MB_Inv

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

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by JonB
        #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
        1
        • JonBJ JonB

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

          M Offline
          M Offline
          MB_Inv
          wrote on 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...

          JonBJ 1 Reply Last reply
          0
          • M MB_Inv

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

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on 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
            0
            • JonBJ JonB

              @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 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
              • JonBJ JonB

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

                JonBJ 1 Reply Last reply
                0
                • M MB_Inv

                  @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

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on 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 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 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

                      • Login

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