Skip to content
  • Agata Cacko's avatar
    Fix Comic Manager race when updating multiple files · ec086e45
    Agata Cacko authored
    Before this commit, in case of updating multiple files at once,
    for example when copying files into the `pages` directory to
    overwrite existing ones, the following would happen:
    
    signal filechanged(file1) -> url = file1 -> wait 200ms ->
        slot updatefile (update `url` file) -> url = ""
    
    signal filechanged(file2) -> url = file2 -> wait 200ms ->
        slot updatefile (update `url` file) -> url = ""
    
    When you update both file1 and file2 at once, a race condition
    would happen and the exact sequence on the timeline would look more like
    this:
    
    signal filechanged(file1) -> url = file1 -> signal filechanged(file2)
       -> url = file2 -> wait 200ms -> slot updatefile (update `url` file,
       which is now `file2`) -> url = "" -> slot updatefile (update `url`
       file, which is now... an empty string
    
    Then the plugin would crash on `realpath()` because the url is empty
    and there is no check for that.
    
    This commit fixes the behaviour by keeping a list of files to update.
    That way in the first phase when lots of `filechanged` signals arrive,
    all files to update are saved into a list and then after 200ms popped
    from the list and updated one by one.
    
    The most elegant solution would be to have QTimer keep the url,
    it would be also possible to make the updatefile slot just update all
    files from the list and return if the list is empty, but it's not
    necessary because the signals will eventually arrive in the correct
    number.
    
    BUG:426701
    
    
    (cherry picked from commit 44a0f225)
    ec086e45