Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
rosettaDeepFixity
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Digital Preservation
rosettaDeepFixity
Commits
d3ed0af3
Commit
d3ed0af3
authored
4 years ago
by
Andreas Romeyke
Browse files
Options
Downloads
Patches
Plain Diff
- improved fixity calculation, now all checksums build at once to avoid multiple reads
parent
b0b9c1cf
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
deep_fixitycheck.pl
+29
-18
29 additions, 18 deletions
deep_fixitycheck.pl
with
29 additions
and
18 deletions
deep_fixitycheck.pl
+
29
−
18
View file @
d3ed0af3
...
...
@@ -28,6 +28,9 @@ use Time::Progress;
use
XML::LibXML::
XPathContext
;
use
Getopt::
Long
;
use
constant
DEBUG
=>
0
;
# no debug
use
Digest::
CRC
;
use
Digest::
MD5
;
use
Digest::
SHA
;
use
Pod::
Usage
;
use
IO::
Handle
;
use
Fcntl
qw(SEEK_END SEEK_SET)
;
...
...
@@ -249,21 +252,33 @@ sub check_file_seekable($$) {
}
# check if referenced file has correct checksum for given algorithm
sub
check_file_fixit
y
($
$$)
{
sub
check_file_fixit
ies
(
$$)
{
my
$fileobj
=
shift
;
my
$result
=
shift
;
my
$fixity_algorithm
=
shift
;
my
$digest_mapping
=
{
# maps Rosetta fixity algorithm names to Perl fixity algorithm names
'
CRC32
'
=>
'
CRC-32
',
'
MD5
'
=>
'
MD5
',
'
SHA1
'
=>
'
SHA-1
',
'
SHA256
'
=>
'
SHA-256
',
'
SHA512
'
=>
'
SHA-512
'
};
my
$digest_name
=
$digest_mapping
->
{
$fixity_algorithm
};
$result
->
{
fixity
}
->
{
$fixity_algorithm
}
=
path
(
$fileobj
->
{
file_mounted
})
->
digest
(
$digest_name
);
my
%digest_mapping
=
(
# maps Rosetta fixity algorithm names to Perl fixity algorithm names
'
CRC32
'
=>
Digest::
CRC
->
new
(
type
=>
"
crc32
"),
'
MD5
'
=>
Digest::
MD5
->
new
(),
'
SHA1
'
=>
Digest::
SHA
->
new
(
1
),
'
SHA256
'
=>
Digest::
SHA
->
new
(
256
),
'
SHA512
'
=>
Digest::
SHA
->
new
(
512
)
);
my
$fh
=
path
(
$fileobj
->
{
file_mounted
})
->
openr
();
binmode
(
$fh
);
my
$buffer
;
while
(
read
(
$fh
,
$buffer
,
128
*
1024
))
{
# 128kB blocks
foreach
my
$fixity_algorithm
(
keys
%digest_mapping
)
{
$digest_mapping
{
$fixity_algorithm
}
->
add
(
$buffer
);
}
}
close
(
$fh
);
foreach
my
$fixity_algorithm
(
keys
%digest_mapping
)
{
if
(
defined
$fileobj
->
{
fixity
}
->
{
$fixity_algorithm
}
&&
length
(
$fileobj
->
{
fixity
}
->
{
$fixity_algorithm
}
)
>
0
)
{
$result
->
{
fixity
}
->
{
$fixity_algorithm
}
=
$digest_mapping
{
$fixity_algorithm
}
->
hexdigest
();
if
(
$result
->
{
fixity
}
->
{
$fixity_algorithm
}
ne
$fileobj
->
{
fixity
}
->
{
$fixity_algorithm
})
{
add_error
(
$fileobj
,
$result
,
"
has fixity
$result
->{fixity}->{
$fixity_algorithm
} for algorithm
$fixity_algorithm
, but
$fileobj
->{fixity}->{
$fixity_algorithm
} was expected
");
die
;
}
}
}
return
$result
;
}
...
...
@@ -342,11 +357,7 @@ if (defined $search_dir && -d "$search_dir") {
$stat
->
{
scansize
}
+=
$result
->
{
size
};
$result
=
check_file_seekable
(
$fileobj
,
$result
);
if
(
$result
->
{
seekable
})
{
foreach
my
$fixity_algorithm
(
@algorithms
)
{
if
(
$fileobj
->
{
fixity
}
->
{
$fixity_algorithm
})
{
$result
=
check_file_fixity
(
$fileobj
,
$result
,
$fixity_algorithm
);
}
}
$result
=
check_file_fixities
(
$fileobj
,
$result
);
}
}
}
...
...
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