Uploaded image for project: 'Qt Installer Framework'
  1. Qt Installer Framework
  2. QTIFW-2120

Devtool can't copy directory if folder contains files, like .txt

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 3.2.2, 4.0.1
    • Tools
    • None
    • Windows 7 SP1, Qt Creator 4.9.1, Qt Version 5.13.0, Qt Installer Framework 3.2.2/4.0.1
    • Windows

    Description

        When I created a installer.exe and I need copy a folder that contains "sample.txt" to "D:
      ", I got this error "Can't create D:\\sample
      sample.txt". So I used devtool.exe to test this, the command line: "devtool.exe operation DO,CopyDirectory,sample,D:
      ". The folder what name is sample contains a "sample.txt" and a subdirectory. Similarly, it shows "Can't create D:\\sample
      sample.txt for output".

        Then, I downloaded source code qt-installer-framework-4.0.1.zip. I found "sourcecode\\src\\libs\\installer
      [copydirectoryoperation.cpp|https://invent.kde.org/qt/installer-framework/installer-framework/-/blob/master/src/libs/installer/copydirectoryoperation.cpp]", some code below:

       

       } else {
                  const QString absolutePath = targetDir.absoluteFilePath(relativePath);
                  ...
                  QFile file(sourceDir.absoluteFilePath(itemName));
                  if (!file.copy(absolutePath)) {
                      qDebug() << "Cannot copy file"
                               << QDir::toNativeSeparators(sourceDir.absoluteFilePath(itemName))
                               << QDir::toNativeSeparators(targetDir.absoluteFilePath(relativePath))
                               << file.errorString();
                  }
       }

       

      Yeah, I thought I got it. When I copy a directory contains some files not only subdirectory, it always copy files firstly, then copy subdirectory. If target directory doesn't exist, it will failed. Because QFile::copy(const QString &name) can't copy a file if the path of this file doesn't exist.

        Finally, I add some code below, it can work normally.

        const QString absolutePath = targetDir.absoluteFilePath(relativePath);
        ...
      + if (!QDir(QFileInfo(absolutePath).path()).exists())
      +         targetDir.mkpath(QFileInfo(absolutePath).path());
        QFile file(sourceDir.absoluteFilePath(itemName));

       

          I also solved my question by another way. I changed my scripts before copy directory, like this:

        component.createOperations();
        if (systemInfo.productType === "windows") { 
      +     component.addOperation ( "Mkdir","D:\\sample" ); 
            component.addOperation ( "CopyDirectory","@InstallerDirPath@\\sample","D:\\",    "forceOverwrite" );
        }

       

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            installerteam Installer Team
            thindjer Hfeng Guan
            Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes