mirror of
https://github.com/vgough/encfs.git
synced 2025-01-14 01:48:30 +01:00
tests: Move helper funtion to common.inc
Also fixes md5fh's fd leak.
This commit is contained in:
parent
1227df72e2
commit
b2943eeed1
tests
14
tests/common.inc
Normal file
14
tests/common.inc
Normal file
@ -0,0 +1,14 @@
|
||||
# Helper function
|
||||
# Get the MD5 sum of the file open at the filehandle
|
||||
sub md5fh
|
||||
{
|
||||
my $fh_orig = shift;
|
||||
open(my $fh, "<&", $fh_orig); # Duplicate the file handle so the seek
|
||||
seek($fh, 0, 0); # does not affect the caller
|
||||
my $md5 = Digest::MD5->new->addfile($fh)->hexdigest;
|
||||
close($fh);
|
||||
return $md5;
|
||||
}
|
||||
|
||||
# As this file will be require()'d, it needs to return true
|
||||
return 1;
|
@ -9,6 +9,8 @@ use File::Temp;
|
||||
use IO::Handle;
|
||||
use Digest::MD5 qw(md5_hex);
|
||||
|
||||
require("tests/common.inc");
|
||||
|
||||
my $tempDir = $ENV{'TMPDIR'} || "/tmp";
|
||||
|
||||
# run unit tests
|
||||
@ -268,17 +270,6 @@ sub encName
|
||||
return $enc;
|
||||
}
|
||||
|
||||
# Helper function
|
||||
# Get the MD5 sum of the file open at the filehandle
|
||||
sub md5fh
|
||||
{
|
||||
my $fh_orig = shift;
|
||||
open(my $fh, "<&", $fh_orig); # Duplicate the file handle so the seek
|
||||
seek($fh, 0, 0); # does not affect the caller
|
||||
return Digest::MD5->new->addfile($fh)->hexdigest;
|
||||
close($fh);
|
||||
}
|
||||
|
||||
# Test symlinks & hardlinks
|
||||
sub links
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user