Dist-Zilla-Plugin-Git-FilePermissions
view release on metacpan or search on metacpan
lib/Dist/Zilla/Plugin/Git/FilePermissions.pm view on Meta::CPAN
if ( $perm eq q{-} ) {
$self->log_debug("Ignoring permissions of file $file");
next FILE;
}
my $current_perm = ( stat $file )[2] & 07777;
if ( $current_perm != $perm ) {
$self->log( sprintf "Setting permission of $file to %o", $perm );
my $rc = chmod $perm, $file;
if ( $rc != 1 ) {
$self->log_fatal( sprintf "Unable to change permissions of file $file to %o", $perm );
}
}
}
return;
}
sub _git_ls_files {
_test_with_config_bin_scripts();
_test_with_config_scripts_unchanged();
}
done_testing();
exit 0;
}
{
# If you run chmod 0644 on a file and read the permissions back with
# stat what you get back depends on your OS. On Unix you get 0644 back
# but on Windows you will get something else back. This function creates
# a hash that maps "permission we set with chmod" to "permission we read
# back with stat",
my %p;
sub _p {
my ($value) = @_;
return $p{$value} if exists $p{$value};
my $tmp_dir = path( tempdir() );
my $file = $tmp_dir->child('file.txt');
$file->spew("hello world\n");
chmod $value, $file or croak "chmod $value, $file: $!";
my $perm = ( stat $file )[2] & 07777;
note( sprintf q{On this system, 'chmod 0%o' results in 0%o}, $value, $perm );
return $p{$value} = $perm;
}
}
my $dir_perm;
sub _configure_root {
my ($root_dir) = @_;
# Create a git repository in the source
# Create some directories
$root_dir->child('bin')->mkpath();
$root_dir->child('scripts')->mkpath();
$root_dir->child('lib')->mkpath();
my @files;
push @files, path($root_dir)->child('bin/a');
$files[-1]->spew();
$git->run( 'add', $files[-1] )->get;
chmod 0755, $files[-1] or croak "chmod 0755, $files[-1]: $!";
push @files, path($root_dir)->child('scripts/b');
$files[-1]->spew();
$git->run( 'add', $files[-1] )->get;
chmod 0600, $files[-1] or croak "chmod 0600, $files[-1]: $!";
push @files, path($root_dir)->child('lib/c.pm');
$files[-1]->spew();
$git->run( 'add', $files[-1] )->get;
chmod 0, $files[-1] or croak "chmod 0, $files[-1]: $!";
push @files, path($root_dir)->child('d');
$files[-1]->spew();
$git->run( 'add', $files[-1] )->get;
chmod 0644, $files[-1] or croak "chmod 0644, $files[-1]: $!";
my $sub_src = _create_submodule();
push @files, path($root_dir)->child('s');
if ( $git->run( 'submodule', 'add', $sub_src, 's' )->await->is_failed ) {
# "protocol.file.allow=always" lets the submodule command clone from
# a local directory. It's necessary as of Git 2.38.1, where the
# default was changed to "user" in response to CVE-2022-39253.
# It isn't a concern here where all repositories involved are
# trusted. For more information, see:
( run in 0.345 second using v1.01-cache-2.11-cpan-8d75d55dd25 )