Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-78734

QFile::copy is unable to copy locked file on MacOS

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 5.15
    • Core: I/O
    • None
    • macOS

    Description

      Steps to reproduce:

      lock a file by right-clicking file and selecting 'Get Info' and then check the 'Locked' checkbox under the General tab.

      execute code

       

      QFile from(path_to_the_locked_file);
      // use a USB drive to reproduce the issue
      // don't know why but it works fine if the target is not external
      from.copy(path_to_the_external_device);
      

      expected behavior: - destination file is created with the same permissions as source file and content is copied.

      actual behavior: error "Cannot create blabla for output" and destination file does not exist

       

      the erroneous code is in the qfile.cpp QFile::copy method search for 

      if (!d->engine()>cloneTo(out.d_func()>engine())) {

      engine cloneTo tries to surprise surprise clone the file but out at this moment is TEMPORARY. So temporary file becomes LOCKED as well as source file because during clone metadata (including permissions) are copied. After this if statement there is

      if (!error && !out.rename(newName)) {

      Obviously, rename fails because the temporary out file is locked.

        

      Possible solution:

      implement cloneDataOnlyTo and cloneMetadataOnlyTo functions in the engine class that copies data and metadata only correspondingly. Replace 

      if (!d->engine()>cloneTo(out.d_func()>engine())) {

      onto

      if (!d->engine()>cloneDataOnlyTo(out.d_func()>engine())) {

      Replace 

      if (!error && !out.rename(newName)) {

       onto

      if (!error && !(out.rename(newName) && d->engine()>cloneMetadataOnlyTo(out.d_func()>engine())) {

       

      Attachments

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

        Activity

          People

            thiago Thiago Macieira
            ahtoh Anton Dyachenko
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes