CTKlib
view release on metacpan or search on metacpan
lib/CTK/Command.pm view on Meta::CPAN
my $dir = $File::Find::dir;
my $file = File::Spec->catfile($dir, $orig);
my (@fromstat) = stat $orig;
print "Normalizing the linefeeds in file $file... ";
file_lf_normalize($orig) or do {
print STDERR "Can't create file $orig: $!\n";
return
};
my $perm = $fromstat[2] || 0;
$perm &= 07777;
eval { chmod $perm, $orig; };
if ($@) {
print STDERR $@, "\n"
} else {
print "ok\n";
}
}}, @ARGV);
}
1;
lib/CTK/Crypt/GPG.pm view on Meta::CPAN
}
$gpgconf ||= File::Spec->catfile($gpghome, GPGCONF);
$gpgopts ||= GPGOPTS;
my @opts = ('# Do not edit this file');
if (ref($gpgopts) eq 'ARRAY') { push @opts, @$gpgopts }
else { push @opts, $gpgopts }
fsave($gpgconf, join("\n", @opts)) or do {
carp(sprintf("Can't save GPG conffile: %s", $gpgconf));
return undef;
};
eval { chmod $gpgconf, 0600 };
# Get version
my @cmd = ();
push(@cmd, $gpgbin, "--homedir", $gpghome, "--options", $gpgconf, "--version");
my $err = "";
my $out = execute( [@cmd], undef, \$err, 1 );
my $version = $out && $out =~ /gpg.+?([0-9\.]+)\s*$/m ? $1 : 0;
if ($version) {
my $tv = pack("U*",split(/\./, $version));
unless ($tv gt pack("U*", 2, 0)) {
lib/CTK/Skel.pm view on Meta::CPAN
my $file = File::Spec->catfile($root, @ds);
if (-e $file) {
$self->_debug(_skip("%s", $file));
next;
}
my $mode = $p->{mode};
my $st = 0;
if ($b64) { $st = bsave($file, decode_base64( $p->{data} )) }
else { $st = bsave($file, CTK::Util::lf_normalize(_ff($p->{data}, $rplc)), 1) }
if ($st && -e $file) {
chmod($mode, $file) if defined($mode);
$self->_debug(_yep("%s", $file));
} else {
$self->_debug(_nope("Can't create file \"%s\" [%o]", $file, $mode // 0));
return 0;
}
}
return 1;
}
sub dirs {
lib/CTK/Skel/Extra.pm view on Meta::CPAN
my $perm = 0755 & 07777;
print sprintf("Creating directory %s... ", $dst_d);
if (-e $dst_d) {
print "skipped. Directory already exists\n";
return;
}
mkdir($dst_d) or do {
print "failed\n";
print STDERR "Can't create $dst_d: $!\n";
};
eval { chmod $perm, $dst_d; };
if ($@) {
print STDERR $@, "\n";
}
print "ok\n";
} else {
print "Skipped: $_\n";
}
}}, ".");
chdir($basedir) or do {
print STDERR "Can't change directory: $!\n";
lib/CTK/Util.pm view on Meta::CPAN
See L<Sys::Path/"prefix">
Tags: CORE, BASE, FILE
=head3 preparedir
$status = preparedir( $dir );
$status = preparedir( \@dirs );
$status = preparedir( \%dirs );
$status = preparedir( $dir, $chmode );
Preparing directory: creation and permission modification.
The function returns true or false.
The $chmode argument should be a octal value, for example:
$status = preparedir( [qw/ foo bar baz /], 0777 );
Tags: BASE, FILE, ATOM
=head3 randchars
$rand = randchars( $n ); # default chars collection: 0..9,'a'..'z','A'..'Z'
$rand = randchars( $n, \@collection ); # Defined chars collection
lib/CTK/Util.pm view on Meta::CPAN
return 0;
}
unless (utime((stat($src))[8,9],$dst)) {
carp("eqtime: Can't change access and modification times on file \"$dst\": $!");
return 0;
}
return 1;
}
sub preparedir {
my $din = shift // return 0;
my $chmod = shift; # 0777
my @dirs;
if (ref($din) eq 'HASH') {
foreach my $k (values %$din) { push @dirs, $k if length($k // '') };
} elsif (ref($din) eq 'ARRAY') {
@dirs = grep { defined($_) && length($_) } @$din;
} else { push @dirs, $din if length($din) }
my $stat = 1;
foreach my $dir (@dirs) {
mkpath( $dir, {verbose => 0} ) unless -e $dir; # mkdir $dir unless -e $dir;
chmod($chmod, $dir) if defined($chmod) && -e $dir;
unless (-d $dir or -l $dir) {
$stat = 0;
carp("preparedir: Directory don't prepare \"$dir\"");
}
}
return $stat;
}
sub scandirs {
my $dir = shift // cwd() // curdir() // '.';
my $mask = shift // '';
( run in 0.264 second using v1.01-cache-2.11-cpan-8d75d55dd25 )