File indexing completed on 2024-03-24 16:47:07

0001 # frozen_string_literal: true
0002 #
0003 # Copyright (C) 2016 Rohan Garg <rohan@garg.io>
0004 #
0005 # This library is free software; you can redistribute it and/or
0006 # modify it under the terms of the GNU Lesser General Public
0007 # License as published by the Free Software Foundation; either
0008 # version 2.1 of the License, or (at your option) version 3, or any
0009 # later version accepted by the membership of KDE e.V. (or its
0010 # successor approved by the membership of KDE e.V.), which shall
0011 # act as a proxy defined in Section 6 of version 3 of the license.
0012 #
0013 # This library is distributed in the hope that it will be useful,
0014 # but WITHOUT ANY WARRANTY; without even the implied warranty of
0015 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0016 # Lesser General Public License for more details.
0017 #
0018 # You should have received a copy of the GNU Lesser General Public
0019 # License along with this library.  If not, see <http://www.gnu.org/licenses/>.
0020 
0021 module Debian
0022   # A class to represent a debian architecture
0023   class Architecture
0024     attr_accessor :arch
0025 
0026     def initialize(arch)
0027       @arch = arch.delete('!')
0028       @negated = arch.start_with?('!')
0029     end
0030 
0031     def negated?
0032       @negated
0033     end
0034 
0035     def qualify?(other)
0036       other = Architecture.new(other) if other.is_a?(String)
0037       success = system('dpkg-architecture', '-a', "#{@arch}",
0038                        '-i', "#{other.arch}", '-f')
0039       other.negated? ^ negated? ? !success : success
0040     end
0041 
0042     def to_s
0043       negated? ? "!#{@arch}" : @arch
0044     end
0045   end
0046 end