Uploaded image for project: 'Qbs ("Cubes")'
  1. Qbs ("Cubes")
  2. QBS-1634

File.copy fails if target exits

    XMLWordPrintable

Details

    • Bug
    • Resolution: Out of scope
    • Not Evaluated
    • None
    • 1.18.0
    • API: JavaScript
    • None

    Description

      The File.copy doesn't copy the file if the target file already exists.

      I saw the issue when working on the android codesign module.

      The codesign module has an enableCodeSigning property which disables signing.

      When set to true then the unsigned package file is signed  into the signed package file.

      When set to false then the unsigned package file is just copied into the "signed" package file.

      After building a signed package, if I disable code signing then the copy doesn't work.

      The copy only works from a fresh build.

      This project illustrates the issue:

      // code placeholder
      import qbs
      import qbs.File
      import qbs.BinaryFile
      
      Project {
          Product {
              name: "copy"
              //type: base.concat(["archiver.input-list", "package"])
              type: "package"
              property bool enableCodeSigning: true
              files: ["code.c"]
              FileTagger {
                  patterns: ["*.c"]
                  fileTags: ["archiver.input-list"]
              }
              Rule {
                  inputs: ["archiver.input-list"]
                  Artifact {
                      filePath: input.fileName + ".signed"
                      fileTags: ["package"]
                  }
                  prepare: {
                      var cmd;
                      if (product.enableCodeSigning) {
                          cmd = new JavaScriptCommand();
                          cmd.description = "signing " + output.fileName;
                          cmd.sourceCode = function() {
                              var source = new BinaryFile(input.filePath, BinaryFile.ReadOnly);
                              var target = new BinaryFile(output.filePath, BinaryFile.WriteOnly);
                              target.resize(0);
                              while (true) {
                                  var data = source.read(1);
                                  if (!data || data.length == 0)
                                      break;
                                  target.write(data);
                              }
                              target.write([0xAB, 0xCD]);
                              source.close();
                              target.close();
                          }
                      } else {
                          cmd = new JavaScriptCommand();
                          cmd.description = "copying without signing " + output.fileName;
                          cmd.source = input.filePath;
                          cmd.target = output.filePath;
                          cmd.sourceCode = function() {
                              //if (File.exists(target ))
                              //    File.remove(target);
                              File.copy(source, target);
                          }
                      }
                      return cmd;
                  }
              }
          }
      }
      

      First step: build the project with enableCodeSigning: true
      The simulated signed package will be build (binary copy of the archive with 0xAB, 0xCD appended).
      Second step: build the project with enableCodeSigning: false
      The package file won't be updated.

      Attachments

        For Gerrit Dashboard: QBS-1634
        # Subject Branch Project Status CR V

        Activity

          People

            kandeler Christian Kandeler
            r.cotty Raphael Cotty
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes