@@ -707,52 +707,7 @@ def safe_epoch
707707 # @return [String]
708708 #
709709 def safe_version
710- version = project . build_version . dup
711-
712- # RPM 4.10+ added support for using the tilde (~) as a way to mark
713- # versions as lower priority in comparisons. More details on this
714- # feature can be found here:
715- #
716- # http://rpm.org/ticket/56
717- #
718- if version =~ /\- /
719- if Ohai [ "platform_family" ] == "wrlinux"
720- converted = version . tr ( "-" , "_" ) # WRL has an elderly RPM version
721- log . warn ( log_key ) do
722- "Omnibus replaces dashes (-) with tildes (~) so pre-release " \
723- "versions get sorted earlier than final versions. However, the " \
724- "version of rpmbuild on Wind River Linux does not support this. " \
725- "All dashes will be replaced with underscores (_). Converting " \
726- "`#{ project . build_version } ' to `#{ converted } '."
727- end
728- else
729- converted = version . tr ( "-" , "~" )
730- log . warn ( log_key ) do
731- "Tildes hold special significance in the RPM package versions. " \
732- "They mark a version as lower priority in RPM's version compare " \
733- "logic. We'll replace all dashes (-) with tildes (~) so pre-release" \
734- "versions get sorted earlier then final versions. Converting" \
735- "`#{ project . build_version } ' to `#{ converted } '."
736- end
737- end
738-
739- version = converted
740- end
741-
742- if version =~ /\A [a-zA-Z0-9\. \+ \: \~ ]+\z /
743- version
744- else
745- converted = version . gsub ( /[^a-zA-Z0-9\. \+ \: \~ ]+/ , "_" )
746-
747- log . warn ( log_key ) do
748- "The `version' component of RPM package names can only include " \
749- "alphabetical characters (a-z, A-Z), numbers (0-9), dots (.), " \
750- "plus signs (+), tildes (~), colons (:) and underscores (_). " \
751- "Converting `#{ project . build_version } ' to `#{ converted } '."
752- end
753-
754- converted
755- end
710+ self . class . safe_version ( project . build_version )
756711 end
757712
758713 #
@@ -883,5 +838,63 @@ def compression_algo(val = nil)
883838 end
884839 end
885840 expose :compression_algo
841+
842+ #
843+ # Return a safe version string out of the input version
844+ # RPM package versions cannot contain dashes, so we will convert them to
845+ # underscores.
846+ # @param [String] string
847+ # the string to sanitize
848+ #
849+ # @return [String]
850+ #
851+ def self . safe_version ( raw_version )
852+ # RPM 4.10+ added support for using the tilde (~) as a way to mark
853+ # versions as lower priority in comparisons. More details on this
854+ # feature can be found here:
855+ #
856+ # http://rpm.org/ticket/56
857+ #
858+ version = raw_version . dup
859+
860+ if version =~ /\- /
861+ if Ohai [ "platform_family" ] == "wrlinux"
862+ converted = version . tr ( "-" , "_" ) # WRL has an elderly RPM version
863+ log . warn ( log_key ) do
864+ "Omnibus replaces dashes (-) with tildes (~) so pre-release " \
865+ "versions get sorted earlier than final versions. However, the " \
866+ "version of rpmbuild on Wind River Linux does not support this. " \
867+ "All dashes will be replaced with underscores (_). Converting " \
868+ "`#{ version } ' to `#{ converted } '."
869+ end
870+ else
871+ converted = version . tr ( "-" , "~" )
872+ log . warn ( log_key ) do
873+ "Tildes hold special significance in the RPM package versions. " \
874+ "They mark a version as lower priority in RPM's version compare " \
875+ "logic. We'll replace all dashes (-) with tildes (~) so pre-release" \
876+ "versions get sorted earlier then final versions. Converting" \
877+ "`#{ version } ' to `#{ converted } '."
878+ end
879+ end
880+
881+ version = converted
882+ end
883+
884+ if version =~ /\A [a-zA-Z0-9\. \+ \: \~ ]+\z /
885+ version
886+ else
887+ converted = version . gsub ( /[^a-zA-Z0-9\. \+ \: \~ ]+/ , "_" )
888+
889+ log . warn ( log_key ) do
890+ "The `version' component of RPM package names can only include " \
891+ "alphabetical characters (a-z, A-Z), numbers (0-9), dots (.), " \
892+ "plus signs (+), tildes (~), colons (:) and underscores (_). " \
893+ "Converting `#{ version } ' to `#{ converted } '."
894+ end
895+
896+ converted
897+ end
898+ end
886899 end
887900end
0 commit comments