Class: Solaris::PatchdiagEntry

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/solaris/patchdiag_entry.rb

Overview

Class to represent a line from Sun’s patchdiag.xref patch “database”. See the following Oracle support publication for format: support.oracle.com/CSP/main/article?cmd=show&type=NOT&doctype=REFERENCE&id=1019527.1

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(patchdiag_line) ⇒ PatchdiagEntry

Returns a new instance of PatchdiagEntry.



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/solaris/patchdiag_entry.rb', line 51

def initialize(patchdiag_line)
  fields = patchdiag_line.split('|')[0..10]
  major, minor, date, @recommended, @security, @obsolete, @bad, @os, archs, pkgs, @synopsis = *fields
  @archs = archs.split( ';' )
  if date == ''
    year, month, day = 1970, 1, 1
  else
    month_s, day_s, year_s = *date.split( '/' )
    year = ( year_s.to_i > 50 ? "19#{year_s}" : "20#{year_s}" ).to_i
    month = Date::ABBR_MONTHNAMES.index( month_s )
    day = day_s.to_i
  end
  @date = Date.new( year, month, day )
  @patch = Patch.new( major, minor )
  @pkgs = pkgs.split( ';' )
end

Instance Attribute Details

#archsObject

An array of architectures for this patch. Values are strings like “sparc”, “i386”.



18
19
20
# File 'lib/solaris/patchdiag_entry.rb', line 18

def archs
  @archs
end

#badObject

The bad field from the patchdiag xref database. Should be either ‘B’ or the empty string. See also PatchdiagEntry#bad?



22
23
24
# File 'lib/solaris/patchdiag_entry.rb', line 22

def bad
  @bad
end

#dateObject

The date of this patch (a Date object).



25
26
27
# File 'lib/solaris/patchdiag_entry.rb', line 25

def date
  @date
end

#osObject

The operating system for this patch, a string like “2.4, ”10“, ”10_x86“ or ”Unbundled“.



29
30
31
# File 'lib/solaris/patchdiag_entry.rb', line 29

def os
  @os
end

#patchObject

The patch object (class Patch) that this entry represents. See also convenience methods PatchdiagEntry#major and PatchdiagEntry#minor.



33
34
35
# File 'lib/solaris/patchdiag_entry.rb', line 33

def patch
  @patch
end

#pkgsObject

An array of packages that pertain to this patch. Values are strings like “SUNWcsr”.



37
38
39
# File 'lib/solaris/patchdiag_entry.rb', line 37

def pkgs
  @pkgs
end

The recommended field from the patchdiag xref database. Should be either ‘R’ or the empty string. See also PatchdiagEntry#recommended?



41
42
43
# File 'lib/solaris/patchdiag_entry.rb', line 41

def recommended
  @recommended
end

#securityObject

The security field from the patchdiag xref database. Should be either ‘S’ or the empty string. See also PatchdiagEntry#security?



45
46
47
# File 'lib/solaris/patchdiag_entry.rb', line 45

def security
  @security
end

#synopsisObject

This synopsis of this patch from the patchdiag xref database. This is a free text field (string).



49
50
51
# File 'lib/solaris/patchdiag_entry.rb', line 49

def synopsis
  @synopsis
end

Instance Method Details

#<=>(other) ⇒ Object

Compare (by delegated comparison of patch versions, see Solaris::Patch#<=>).



158
159
160
# File 'lib/solaris/patchdiag_entry.rb', line 158

def <=>(other)
  self.patch <=> other.patch
end

#bad?Boolean

Boolean, returns true if this patch is marked as “bad” in the patchdiag xref database.

Returns:

  • (Boolean)


70
# File 'lib/solaris/patchdiag_entry.rb', line 70

def bad? ; @bad == 'B' end

#download_patch!(opts = {}) ⇒ Object

Download this patch. For options hash see Patch#download!.



73
74
75
# File 'lib/solaris/patchdiag_entry.rb', line 73

def download_patch!(opts={}) ;
  @patch.download_patch!( opts )
end

#download_readme!(opts = {}) ⇒ Object

Download the README for this patch. For options hash see Patch#download!.



78
79
80
# File 'lib/solaris/patchdiag_entry.rb', line 78

def download_readme!(opts={})
  @patch.download_readme!( opts )
end

#majorObject

Returns this entries major patch number as an integer.



83
# File 'lib/solaris/patchdiag_entry.rb', line 83

def major ; @patch.major end

#minorObject

Returns this entries minor patch number as an integer.



86
# File 'lib/solaris/patchdiag_entry.rb', line 86

def minor ; @patch.minor end

#obsolete?Boolean

Boolean, returns true if this patch is marked as “obsolete” in the patchdiag xref database.

Returns:

  • (Boolean)


90
# File 'lib/solaris/patchdiag_entry.rb', line 90

def obsolete? ; @obsolete == 'O' end

#recommended?Boolean

Boolean, returns true if this patch is marked as “recommended” in the patchdiag xref database.

Returns:

  • (Boolean)


94
# File 'lib/solaris/patchdiag_entry.rb', line 94

def recommended? ; @recommended == 'R' end

#security?Boolean

Boolean, returns true if this patch is marked as “security” in the patchdiag xref database.

Returns:

  • (Boolean)


98
# File 'lib/solaris/patchdiag_entry.rb', line 98

def security? ; @security == 'S' end

#successorObject

Return the Solaris::Patch by which this entry is obsoleted. Throws Solaris::Patch::NotObsolete if this entry is not obsolete. Throws Solaris::Patch::MultipleSuccessors if this entry has more than one successor. Throws Solaris::Patch::InvalidSuccessor if the “obsoleted by” entry cannot be understood.



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/solaris/patchdiag_entry.rb', line 106

def successor
  # I <3 consistency:
  # Obsoleted by : XXXXXX-XX
  # Obsoleted by: XXXXXX-XX
  # OBSOLETED by: XXXXXX
  # Obsoleted by: XXXXXX-XX OBSOLETED by WITHDRAWN
  # OBSOLETED by WITHDRAWN
  # OBSOLETED by XXXXXX
  # OBSOLETED by XXXXXX and XXXXXX # we ignore this pattern, see below
  # Obsoleted by XXXXXX-XX:
  # OBSOLETED by XXXXXX-XX:
  # WITHDRAWN Obsoleted by: XXXXXX-XX
  # WITHDRAWN PATCH Obsolete by:
  # WITHDRAWN PATCH Obsoleted by:
  # WITHDRAWN PATCH Obsoleted by XXXXXX-XX:

  # Fail if this entry is not actually obsolete
  raise Solaris::Patch::NotObsolete,
    "Entry #{patch.inspect} not obsolete" unless obsolete?

  # Fail on these two entries from 1999 since they are the only ones ever
  # that are succeeded by two patches each
  raise Solaris::Patch::MultipleSuccessors,
    "More than one successor for entry #{patch.inspect}" if [ 105716, 105717 ].include?( self.major )

  # See if we can find a successor
  if synopsis =~ /obsolete(d?) by\s*(:?)\s*(\d+(-\d+)?)/i
    Patch.new( $3 )
  else
    raise Solaris::Patch::InvalidSuccessor,
      "Failed to parse successor to obsolete patchdiag entry for patch #{patch.inspect}"
  end
end

#to_sObject

Output this patchdiag xref entry as a string, in format of Oracle’s database.



142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/solaris/patchdiag_entry.rb', line 142

def to_s
  [ patch.major,
    Patch.pad_minor( patch.minor ),
    date_s,
    @recommended,
    @security,
    @obsolete,
    @bad,
    @os,
    join_semis( @archs ),
    join_semis( @pkgs ),
    @synopsis
  ].join('|')
end