reapack

Package manager for REAPER
Log | Files | Refs | Submodules | README | LICENSE

task.cpp (1881B)


      1 /* ReaPack: Package manager for REAPER
      2  * Copyright (C) 2015-2025  Christian Fillion
      3  *
      4  * This program is free software: you can redistribute it and/or modify
      5  * it under the terms of the GNU Lesser General Public License as published by
      6  * the Free Software Foundation, either version 3 of the License, or
      7  * (at your option) any later version.
      8  *
      9  * This program is distributed in the hope that it will be useful,
     10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     12  * GNU Lesser General Public License for more details.
     13  *
     14  * You should have received a copy of the GNU Lesser General Public License
     15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
     16  */
     17 
     18 #include "task.hpp"
     19 
     20 #include "archive.hpp"
     21 #include "config.hpp"
     22 #include "download.hpp"
     23 #include "errors.hpp"
     24 #include "filesystem.hpp"
     25 #include "index.hpp"
     26 #include "reapack.hpp"
     27 #include "transaction.hpp"
     28 
     29 UninstallTask::UninstallTask(const Registry::Entry &re, Transaction *tx)
     30   : Task(tx), m_entry(std::move(re))
     31 {
     32 }
     33 
     34 bool UninstallTask::start()
     35 {
     36   tx()->registry()->getFiles(m_entry).swap(m_files);
     37 
     38   // allow conflicting packages to be installed
     39   tx()->registry()->forget(m_entry);
     40 
     41   return true;
     42 }
     43 
     44 void UninstallTask::commit()
     45 {
     46   for(const auto &file : m_files) {
     47     if(!FS::exists(file.path) || FS::removeRecursive(file.path))
     48       tx()->receipt()->addRemoval(file.path);
     49     else
     50       tx()->receipt()->addError({FS::lastError(), file.path.join()});
     51 
     52     tx()->registerFile({false, m_entry, file});
     53   }
     54 
     55   tx()->registry()->forget(m_entry);
     56 }
     57 
     58 FlagsTask::FlagsTask(const Registry::Entry &re, const int flags, Transaction *tx)
     59   : Task(tx), m_entry(std::move(re)), m_flags(flags)
     60 {
     61 }
     62 
     63 void FlagsTask::commit()
     64 {
     65   tx()->registry()->setFlags(m_entry, m_flags);
     66   tx()->receipt()->setPackageChanged();
     67 }