Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
brew
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to JiHu GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
KMSCAKKSCFKA AKFACAMADCAS
brew
Commits
f072f40b
Commit
f072f40b
authored
11 years ago
by
Jack Nagel
Browse files
Options
Downloads
Patches
Plain Diff
Extract ResourceAuditor from FormulaAuditor
parent
a7e1dbae
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Library/Homebrew/cmd/audit.rb
+75
-46
75 additions, 46 deletions
Library/Homebrew/cmd/audit.rb
with
75 additions
and
46 deletions
Library/Homebrew/cmd/audit.rb
+
75
−
46
View file @
f072f40b
...
...
@@ -272,52 +272,9 @@ class FormulaAuditor
def
audit_specs
problem
"Head-only (no stable download)"
if
f
.
head_only?
[
:stable
,
:devel
].
each
do
|
spec
|
s
=
f
.
send
(
spec
)
next
if
s
.
nil?
if
s
.
version
.
to_s
.
empty?
problem
"Invalid or missing
#{
spec
}
version"
else
version_text
=
s
.
version
unless
s
.
version
.
detected_from_url?
version_url
=
Version
.
detect
(
s
.
url
,
s
.
specs
)
if
version_url
.
to_s
==
version_text
.
to_s
&&
s
.
version
.
instance_of?
(
Version
)
problem
"
#{
spec
}
version
#{
version_text
}
is redundant with version scanned from URL"
end
end
if
s
.
version
.
to_s
=~
/^v/
problem
"
#{
spec
}
version
#{
s
.
version
}
should not have a leading 'v'"
end
cksum
=
s
.
checksum
next
if
cksum
.
nil?
case
cksum
.
hash_type
when
:md5
problem
"md5 checksums are deprecated, please use sha1 or sha256"
next
when
:sha1
then
len
=
40
when
:sha256
then
len
=
64
end
if
cksum
.
empty?
problem
"
#{
cksum
.
hash_type
}
is empty"
else
problem
"
#{
cksum
.
hash_type
}
should be
#{
len
}
characters"
unless
cksum
.
hexdigest
.
length
==
len
problem
"
#{
cksum
.
hash_type
}
contains invalid characters"
unless
cksum
.
hexdigest
=~
/^[a-fA-F0-9]+$/
problem
"
#{
cksum
.
hash_type
}
should be lowercase"
unless
cksum
.
hexdigest
==
cksum
.
hexdigest
.
downcase
end
end
# Check for :using that is already detected from the url
@specs
.
each
do
|
s
|
next
if
s
.
using
.
nil?
url_strategy
=
DownloadStrategyDetector
.
detect
(
s
.
url
)
using_strategy
=
DownloadStrategyDetector
.
detect
(
''
,
s
.
using
)
problem
"redundant :using specification in url or head"
if
url_strategy
==
using_strategy
@specs
.
each
do
|
spec
|
ra
=
ResourceAuditor
.
new
(
spec
).
audit
problems
.
concat
(
ra
.
problems
)
end
end
...
...
@@ -624,3 +581,75 @@ class FormulaAuditor
@problems
<<
p
end
end
class
ResourceAuditor
attr_reader
:problems
attr_reader
:version
,
:checksum
,
:using
,
:specs
,
:url
def
initialize
(
resource
)
@version
=
resource
.
version
@checksum
=
resource
.
checksum
@url
=
resource
.
url
@using
=
resource
.
using
@specs
=
resource
.
specs
@problems
=
[]
end
def
audit
audit_version
audit_checksum
audit_download_strategy
self
end
def
audit_version
if
version
.
to_s
.
empty?
problem
"invalid or missing version"
elsif
not
version
.
detected_from_url?
version_text
=
version
version_url
=
Version
.
detect
(
url
,
specs
)
if
version_url
.
to_s
==
version_text
.
to_s
&&
version
.
instance_of?
(
Version
)
problem
"version
#{
version_text
}
is redundant with version scanned from URL"
end
end
if
version
.
to_s
=~
/^v/
problem
"version
#{
version
}
should not have a leading 'v'"
end
end
def
audit_checksum
return
unless
checksum
case
checksum
.
hash_type
when
:md5
problem
"MD5 checksums are deprecated, please use SHA1 or SHA256"
return
when
:sha1
then
len
=
40
when
:sha256
then
len
=
64
end
if
checksum
.
empty?
problem
"
#{
checksum
.
hash_type
}
is empty"
else
problem
"
#{
checksum
.
hash_type
}
should be
#{
len
}
characters"
unless
checksum
.
hexdigest
.
length
==
len
problem
"
#{
checksum
.
hash_type
}
contains invalid characters"
unless
checksum
.
hexdigest
=~
/^[a-fA-F0-9]+$/
problem
"
#{
checksum
.
hash_type
}
should be lowercase"
unless
checksum
.
hexdigest
==
checksum
.
hexdigest
.
downcase
end
end
def
audit_download_strategy
return
unless
using
url_strategy
=
DownloadStrategyDetector
.
detect
(
url
)
using_strategy
=
DownloadStrategyDetector
.
detect
(
''
,
using
)
if
url_strategy
==
using_strategy
problem
"redundant :using specification in URL"
end
end
def
problem
text
@problems
<<
text
end
end
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment