|
NAMENo::Worries::Stat - stat() handling without worriesSYNOPSISuse No::Worries::Stat qw(*); @stat = stat($path) or die; printf("type is %s\n", stat_type($stat[ST_MODE])); printf("size is %d\n", $stat[ST_SIZE]); printf("user can read\n") if $stat[ST_MODE] & S_IRUSR; # make sure "/bin/ls" is owned by root and has the right permissions stat_ensure("/bin/ls", user => "root", mode => 0755); # make sure "/var/log" is not group or world writable stat_ensure("/var/log", mode => "-022"); # idem but using the S_* constants stat_ensure("/var/log", mode => "-" . (S_IWGRP|S_IWOTH)); DESCRIPTIONThis module eases file status handling by providing convenient constants and functions to get, set and manipulate file status information. All the functions die() on error.CONSTANTSThis module provides the following constants to ease access to stat() fields (none of them being exported by default):
In addition, it also optionally exports all the ":mode" constants from Fcntl. This way, all the stat() related constants can be imported in a uniform way. FUNCTIONSThis module provides the following functions (none of them being exported by default):
The "mode" option of stat_ensure() can be given:
Note: the number after "+" or "-" will be interpreted as being octal only if it starts with "0". You should therefore use "+0111" or "+".oct(111) to enable the executable bits but not "+111" which is the same as "+0157". The "callback" option of stat_ensure() will receive the given path and a string describing what is about to be changed. It must return true to tell stat_ensure() to indeed perform the changes. Here is for insatnce how a "noaction" option could be implemented: sub noaction ($$) { my($path, $change) = @_; printf("did not change %s of %s\n", $change, $path); return(0); } foreach my $path (@paths) { stat_ensure($path, user => "root", mode => 0755, callback => \&noaction); } SEE ALSOFcntl, No::Worries.AUTHORLionel Cons <http://cern.ch/lionel.cons>Copyright (C) CERN 2012-2019
Visit the GSP FreeBSD Man Page Interface. |