No::Worries::Stat(3)
π No::Worries::Stat β stat() without the stress π
okay so welcome to the No::Worries::Stat(3) page, bestie β itβs giving User Contributed Perl Documentation, but make it cute. This is your little file-status helper module, and it wants you to understand every single thing. π«Ά
β¨ NAME β¨
No::Worries::Stat β stat() handling without worries. Thatβs the whole vibe, no cap. π
π¦ SYNOPSIS π¦
use 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));
π DESCRIPTION π
This 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 β so no quiet little failures, okay? π
π CONSTANTS π
This module provides the following constants to ease access to stat() fields (none of them being exported by default):
ST_DEVβ ID of device containing fileST_INOβ inode numberST_MODEβ protectionST_NLINKβ number of hard linksST_UIDβ user ID of ownerST_GIDβ group ID of ownerST_RDEVβ device ID (if special file)ST_SIZEβ total size, in bytesST_ATIMEβ time of last accessST_MTIMEβ time of last modificationST_CTIMEβ time of last status changeST_BLKSIZEβ blocksize for filesystem I/OST_BLOCKSβ number of 512B blocks allocated
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. Slay. π
π FUNCTIONS π
This module provides the following functions (none of them being exported by default):
stat_type(MODE)
Given the file mode (ST_MODE field), return the file type as a string. The possible return values are: block device, character device, directory, door, event port, network file, pipe, plain file, socket, symlink, unknown and whiteout. π¦
stat_ensure(PATH[, OPTIONS])
Make sure the given path has the expected file status (w.r.t. stat()) and call chown(), chmod() or utime() if needed, returning the number of changes performed. Supported options:
userβ expected user name or uidgroupβ expected group name or gidmodeβ expected mode specification (see below)mtimeβ expected modification timefollowβ follow symbolic links (default is to skip them)callbackβ code to be executed before changing something (see below)
The mode option of stat_ensure() can be given:
NUMBERβ an absolute value like0755, meaning that mode must be equal to it+NUMBERβ a list of bits that must be set, e.g.+0111for "executable for all"-NUMBERβ a list of bits that must be clear, e.g.-022for not writable by group or other
Note, bestie: the number after+or-will be interpreted as being octal only if it starts with0. You should therefore use+0111or+.oct(111) to enable the executable bits but not+111which is the same as+0157. Lowkey important, donβt skip it. π₯
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βs 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 ALSO π
Fcntl, No::Worries. Go peek at them, theyβre part of the friend group. π
π AUTHOR π
Lionel Cons <http://cern.ch/lionel.cons>
Copyright (C) CERN 2012-2019
π Thatβs the whole page, bestie β brought to you by No::Worries::Stat(3), perl v5.32.1, and 2021-10-18. Periodt. π
π¦ where this page comes from
- epel 9: perl-No-Worries 1.7-1.el9 Β· GPL+ or Artistic
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms