gzip/gunzip are found to change inode number, thus ownership are not preserved if opened by another owner.
Unit Test failed due to a feature in gzip/gunzip utility. The discussion about gzip/gunzip is all over, I want to push a little further
Real problem need a real solution. Can we get around to have the same fileowner on test6?
The original owner has uid 500, pass all unit tests
ok 1 - /shared/shared/colourbar.nii.gz Found
ok 2 - original fileowner <500>
ok 3 - original inode<692254>
gunzip -f /shared/shared/colourbar.nii.gz
ok 4 - fileowner after gunzip <500>
ok 5 - inode after gunzip<692255>
gzip -f /shared/shared/colourbar.nii
ok 6 - fileowner after gzip <500>
ok 7 - inode after gzip<692254>
Joe has uid of 504, test 6 failed
ok 1 - /shared/shared/colourbar.nii.gz Found
ok 2 - original fileowner <500>
ok 3 - original inode<692254>
gunzip -f /shared/shared/colourbar.nii.gz
not ok 4 - fileowner after gunzip <504>
ok 5 - inode after gunzip<692255>
gzip -f /shared/shared/colourbar.nii
not ok 6 - fileowner after gzip <504>
ok 7 - inode after gzip<692254>
The original test script is here:
#!/usr/bin/perl
use strict;
use warnings;
use Test::More ;
return 1 unless $0 eq __FILE__;
main(@ARGV) if $0 eq __FILE__;
sub mock_gzip{
my $file = $_[0];
my $cmd = "gzip -f $file";
print "$cmd\n";
system($cmd);
}
sub mock_gunzip{
my $file = $_[0];
my $cmd = "gunzip -f $file";
print "$cmd\n";
system($cmd);
}
sub fileowner{
my $file = $_[0];
my $uid = `stat -c %u $file`;
chomp($uid);
return $uid;
}
sub get_inode{
my $file =$_[0];
my $inode = `stat -c %i $file`;
chomp($inode);
return $inode;
}
sub main{
#simulate real life situation - user A
my $file = "/shared/shared/colourbar.nii.gz";
my $fileu = $file;
$fileu =~ s/.gz$//g;
ok(-e $file,"$file Found\n");
my $fileowner = fileowner($file);
ok($fileowner>0,"original fileowner <$fileowner>\n");
my $inode = get_inode($file);
ok($inode>0,"original inode<$inode>\n");
# user B - gunzip/gzip owner changed
mock_gunzip($file);
my $fileowner_gunzip = fileowner($fileu);
ok($fileowner_gunzip==$fileowner,"fileowner after gunzip <$fileowner_gunzip>\n");
my $inode_gunzip = get_inode($fileu);
ok($inode_gunzip>0,"inode after gunzip<$inode_gunzip>\n");
mock_gzip($fileu);
my $fileowner_gzip = fileowner($file);
ok($fileowner_gzip==$fileowner,"fileowner after gzip <$fileowner_gzip>\n");
my $inode_gzip = get_inode($file);
ok($inode_gzip==$inode,"inode after gzip<$inode_gzip>\n");
# solution, or verified no solution to be decided
}
Aucun commentaire:
Enregistrer un commentaire