LCOV - code coverage report
Current view: top level - muse/framework/update/internal - downloadfiledevice.cpp Coverage Total Hit
Test: filtered_coverage.info Lines: 37.0 % 27 10
Test Date: 2026-11-05 04:07:02

            Line data    Source code
       1              : /*
       2              :  * SPDX-License-Identifier: GPL-3.0-only
       3              :  * MuseScore-CLA-applies
       4              :  *
       5              :  * MuseScore Studio
       6              :  * Music Composition & Notation
       7              :  *
       8              :  * Copyright (C) 2026 MuseScore Limited and others
       9              :  *
      10              :  * This program is free software: you can redistribute it and/or modify
      11              :  * it under the terms of the GNU General Public License version 3 as
      12              :  * published by the Free Software Foundation.
      13              :  *
      14              :  * This program is distributed in the hope that it will be useful,
      15              :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      16              :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      17              :  * GNU General Public License for more details.
      18              :  *
      19              :  * You should have received a copy of the GNU General Public License
      20              :  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
      21              :  */
      22              : #include "downloadfiledevice.h"
      23              : 
      24              : using namespace muse;
      25              : using namespace muse::update;
      26              : 
      27           14 : DownloadFileDevice::DownloadFileDevice(const io::path_t& path, io::IODevice::OpenMode mode, QObject* parent)
      28           14 :     : QIODevice(parent), m_stream(path), m_mode(mode)
      29              : {
      30           14 : }
      31              : 
      32           14 : DownloadFileDevice::~DownloadFileDevice()
      33              : {
      34           14 :     DownloadFileDevice::close();
      35           14 : }
      36              : 
      37            0 : bool DownloadFileDevice::isSequential() const
      38              : {
      39            0 :     return true;
      40              : }
      41              : 
      42            0 : bool DownloadFileDevice::open(QIODevice::OpenMode)
      43              : {
      44              :     //! NOTE: Ignore the mode requested by the network manager (WriteOnly, which
      45              :     //! truncates); open the file in the mode chosen at construction so that an
      46              :     //! interrupted download can be resumed via Append.
      47            0 :     if (!m_stream.open(m_mode)) {
      48            0 :         setErrorString(QString::fromStdString(m_stream.errorString()));
      49            0 :         return false;
      50              :     }
      51              : 
      52            0 :     QIODevice::open(QIODevice::WriteOnly);
      53            0 :     return true;
      54              : }
      55              : 
      56           14 : void DownloadFileDevice::close()
      57              : {
      58           14 :     if (m_stream.isOpen()) {
      59            0 :         m_stream.close();
      60              :     }
      61           14 :     QIODevice::close();
      62           14 : }
      63              : 
      64            0 : qint64 DownloadFileDevice::readData(char*, qint64)
      65              : {
      66            0 :     return -1;
      67              : }
      68              : 
      69            0 : qint64 DownloadFileDevice::writeData(const char* data, qint64 len)
      70              : {
      71            0 :     const size_t written = m_stream.write(reinterpret_cast<const uint8_t*>(data), static_cast<size_t>(len));
      72            0 :     if (static_cast<qint64>(written) != len) {
      73            0 :         setErrorString(QString::fromStdString(m_stream.errorString()));
      74            0 :         return -1;
      75              :     }
      76              : 
      77            0 :     return static_cast<qint64>(written);
      78              : }
        

Generated by: LCOV version 2.0-1