⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 file::path.3

📁 视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.
💻 3
📖 第 1 页 / 共 2 页
字号:
If a system error prevents a directory from being created, then the\&\f(CW\*(C`mkpath\*(C'\fR function throws a fatal error with \f(CW\*(C`Carp::croak\*(C'\fR. This errorcan be trapped with an \f(CW\*(C`eval\*(C'\fR block:.PP.Vb 4\&  eval { mkpath($dir) };\&  if ($@) {\&    print "Couldn\*(Aqt create $dir: $@";\&  }.Ve.PPIn the traditional \s-1API\s0, \f(CW\*(C`rmtree\*(C'\fR takes three arguments:.IP "\(bu" 4the root of the subtree to delete, or a reference to a list ofroots. All of the files and directories below each root, as wellas the roots themselves, will be deleted. If you want to keepthe roots themselves, you must use the modern \s-1API\s0..IP "\(bu" 4a boolean value, which if \s-1TRUE\s0 will cause \f(CW\*(C`rmtree\*(C'\fR to print amessage each time it examines a file, giving the name of the file,and indicating whether it's using \f(CW\*(C`rmdir\*(C'\fR or \f(CW\*(C`unlink\*(C'\fR to removeit, or that it's skipping it.  (defaults to \s-1FALSE\s0).IP "\(bu" 4a boolean value, which if \s-1TRUE\s0 will cause \f(CW\*(C`rmtree\*(C'\fR to skip anyfiles to which you do not have delete access (if running under \s-1VMS\s0)or write access (if running under another \s-1OS\s0). This will changein the future when a criterion for 'delete permission' under OSsother than \s-1VMS\s0 is settled.  (defaults to \s-1FALSE\s0).PPIt returns the number of files, directories and symlinks successfullydeleted.  Symlinks are simply deleted and not followed..PPNote also that the occurrence of errors in \f(CW\*(C`rmtree\*(C'\fR using thetraditional interface can be determined \fIonly\fR by trapping diagnosticmessages using \f(CW$SIG{_\|_WARN_\|_}\fR; it is not apparent from the returnvalue. (The modern interface may use the \f(CW\*(C`error\*(C'\fR parameter torecord any problems encountered)..Sh "\s-1ERROR\s0 \s-1HANDLING\s0".IX Subsection "ERROR HANDLING"If \f(CW\*(C`mkpath\*(C'\fR or \f(CW\*(C`rmtree\*(C'\fR encounter an error, a diagnostic messagewill be printed to \f(CW\*(C`STDERR\*(C'\fR via \f(CW\*(C`carp\*(C'\fR (for non-fatal errors),or via \f(CW\*(C`croak\*(C'\fR (for fatal errors)..PPIf this behaviour is not desirable, the \f(CW\*(C`error\*(C'\fR attribute may beused to hold a reference to a variable, which will be used to storethe diagnostics. The result is a reference to a list of hashreferences. For each hash reference, the key is the name of thefile, and the value is the error message (usually the contents of\&\f(CW$!\fR). An example usage looks like:.PP.Vb 5\&  rmpath( \*(Aqfoo/bar\*(Aq, \*(Aqbar/rat\*(Aq, {error => \emy $err} );\&  for my $diag (@$err) {\&    my ($file, $message) = each %$diag;\&    print "problem unlinking $file: $message\en";\&  }.Ve.PPIf no errors are encountered, \f(CW$err\fR will point to an empty list(thus there is no need to test for \f(CW\*(C`undef\*(C'\fR). If a general erroris encountered (for instance, \f(CW\*(C`rmtree\*(C'\fR attempts to remove a directorytree that does not exist), the diagnostic key will be empty, onlythe value will be set:.PP.Vb 7\&  rmpath( \*(Aq/no/such/path\*(Aq, {error => \emy $err} );\&  for my $diag (@$err) {\&    my ($file, $message) = each %$diag;\&    if ($file eq \*(Aq\*(Aq) {\&      print "general error: $message\en";\&    }\&  }.Ve.Sh "\s-1NOTES\s0".IX Subsection "NOTES"\&\f(CW\*(C`File::Path\*(C'\fR blindly exports \f(CW\*(C`mkpath\*(C'\fR and \f(CW\*(C`rmtree\*(C'\fR into thecurrent namespace. These days, this is considered bad style, butto change it now would break too much code. Nonetheless, you areinvited to specify what it is you are expecting to use:.PP.Vb 1\&  use File::Path \*(Aqrmtree\*(Aq;.Ve.PP\fI\s-1HEURISTICS\s0\fR.IX Subsection "HEURISTICS".PPThe functions detect (as far as possible) which way they are beingcalled and will act appropriately. It is important to remember thatthe heuristic for detecting the old style is either the presenceof an array reference, or two or three parameters total and secondand third parameters are numeric. Hence....PP.Vb 1\&    mkpath 486, 487, 488;.Ve.PP\&... will not assume the modern style and create three directories, ratherit will create one directory verbosely, setting the permission to0750 (488 being the decimal equivalent of octal 750). Here, oldstyle trumps new. It must, for backwards compatibility reasons..PPIf you want to ensure there is absolutely no ambiguity about whichway the function will behave, make sure the first parameter is areference to a one-element list, to force the old style interpretation:.PP.Vb 1\&    mkpath [486], 487, 488;.Ve.PPand get only one directory created. Or add a reference to an emptyparameter hash, to force the new style:.PP.Vb 1\&    mkpath 486, 487, 488, {};.Ve.PP\&... and hence create the three directories. If the empty hashreference seems a little strange to your eyes, or you suspect asubsequent programmer might \fIhelpfully\fR optimise it away, youcan add a parameter set to a default value:.PP.Vb 1\&    mkpath 486, 487, 488, {verbose => 0};.Ve.PP\fI\s-1SECURITY\s0 \s-1CONSIDERATIONS\s0\fR.IX Subsection "SECURITY CONSIDERATIONS".PPThere were race conditions 1.x implementations of File::Path's\&\f(CW\*(C`rmtree\*(C'\fR function (although sometimes patched depending on the \s-1OS\s0distribution or platform). The 2.0 version contains code to avoid theproblem mentioned in \s-1CVE\-2002\-0435\s0..PPSee the following pages for more information:.PP.Vb 3\&  http://bugs.debian.org/cgi\-bin/bugreport.cgi?bug=286905\&  http://www.nntp.perl.org/group/perl.perl5.porters/2005/01/msg97623.html\&  http://www.debian.org/security/2005/dsa\-696.Ve.PPAdditionally, unless the \f(CW\*(C`safe\*(C'\fR parameter is set (or thethird parameter in the traditional interface is \s-1TRUE\s0), should a\&\f(CW\*(C`rmtree\*(C'\fR be interrupted, files that were originally in read-onlymode may now have their permissions set to a read-write (or \*(L"delete\&\s-1OK\s0\*(R") mode..SH "DIAGNOSTICS".IX Header "DIAGNOSTICS"\&\s-1FATAL\s0 errors will cause the program to halt (\f(CW\*(C`croak\*(C'\fR), since theproblem is so severe that it would be dangerous to continue. (Thiscan always be trapped with \f(CW\*(C`eval\*(C'\fR, but it's not a good idea. Underthe circumstances, dying is the best thing to do)..PP\&\s-1SEVERE\s0 errors may be trapped using the modern interface. If thethey are not trapped, or the old interface is used, such an errorwill cause the program will halt..PPAll other errors may be trapped using the modern interface, otherwisethey will be \f(CW\*(C`carp\*(C'\fRed about. Program execution will not be halted..IP "mkdir [path]: [errmsg] (\s-1SEVERE\s0)" 4.IX Item "mkdir [path]: [errmsg] (SEVERE)"\&\f(CW\*(C`mkpath\*(C'\fR was unable to create the path. Probably some sort ofpermissions error at the point of departure, or insufficient resources(such as free inodes on Unix)..IP "No root path(s) specified" 4.IX Item "No root path(s) specified"\&\f(CW\*(C`mkpath\*(C'\fR was not given any paths to create. This message is onlyemitted if the routine is called with the traditional interface.The modern interface will remain silent if given nothing to do..IP "No such file or directory" 4.IX Item "No such file or directory"On Windows, if \f(CW\*(C`mkpath\*(C'\fR gives you this warning, it may mean thatyou have exceeded your filesystem's maximum path length..IP "cannot fetch initial working directory: [errmsg]" 4.IX Item "cannot fetch initial working directory: [errmsg]"\&\f(CW\*(C`rmtree\*(C'\fR attempted to determine the initial directory by calling\&\f(CW\*(C`Cwd::getcwd\*(C'\fR, but the call failed for some reason. No attemptwill be made to delete anything..IP "cannot stat initial working directory: [errmsg]" 4.IX Item "cannot stat initial working directory: [errmsg]"\&\f(CW\*(C`rmtree\*(C'\fR attempted to stat the initial directory (after havingsuccessfully obtained its name via \f(CW\*(C`getcwd\*(C'\fR), however, the callfailed for some reason. No attempt will be made to delete anything..IP "cannot chdir to [dir]: [errmsg]" 4.IX Item "cannot chdir to [dir]: [errmsg]"\&\f(CW\*(C`rmtree\*(C'\fR attempted to set the working directory in order tobegin deleting the objects therein, but was unsuccessful. This isusually a permissions issue. The routine will continue to deleteother things, but this directory will be left intact..IP "directory [dir] changed before chdir, expected dev=[n] inode=[n], actual dev=[n] ino=[n], aborting. (\s-1FATAL\s0)" 4.IX Item "directory [dir] changed before chdir, expected dev=[n] inode=[n], actual dev=[n] ino=[n], aborting. (FATAL)"\&\f(CW\*(C`rmtree\*(C'\fR recorded the device and inode of a directory, and thenmoved into it. It then performed a \f(CW\*(C`stat\*(C'\fR on the current directoryand detected that the device and inode were no longer the same. Asthis is at the heart of the race condition problem, the programwill die at this point..IP "cannot make directory [dir] read+writeable: [errmsg]" 4.IX Item "cannot make directory [dir] read+writeable: [errmsg]"\&\f(CW\*(C`rmtree\*(C'\fR attempted to change the permissions on the current directoryto ensure that subsequent unlinkings would not run into problems,but was unable to do so. The permissions remain as they were, andthe program will carry on, doing the best it can..IP "cannot read [dir]: [errmsg]" 4.IX Item "cannot read [dir]: [errmsg]"\&\f(CW\*(C`rmtree\*(C'\fR tried to read the contents of the directory in orderto acquire the names of the directory entries to be unlinked, butwas unsuccessful. This is usually a permissions issue. Theprogram will continue, but the files in this directory will remainafter the call..IP "cannot reset chmod [dir]: [errmsg]" 4.IX Item "cannot reset chmod [dir]: [errmsg]"\&\f(CW\*(C`rmtree\*(C'\fR, after having deleted everything in a directory, attemptedto restore its permissions to the original state but failed. Thedirectory may wind up being left behind..IP "cannot chdir to [parent\-dir] from [child\-dir]: [errmsg], aborting. (\s-1FATAL\s0)" 4.IX Item "cannot chdir to [parent-dir] from [child-dir]: [errmsg], aborting. (FATAL)"\&\f(CW\*(C`rmtree\*(C'\fR, after having deleted everything and restored the permissionsof a directory, was unable to chdir back to the parent. This is usuallya sign that something evil this way comes..IP "cannot stat prior working directory [dir]: [errmsg], aborting. (\s-1FATAL\s0)" 4.IX Item "cannot stat prior working directory [dir]: [errmsg], aborting. (FATAL)"\&\f(CW\*(C`rmtree\*(C'\fR was unable to stat the parent directory after have returnedfrom the child. Since there is no way of knowing if we returned towhere we think we should be (by comparing device and inode) the onlyway out is to \f(CW\*(C`croak\*(C'\fR..IP "previous directory [parent\-dir] changed before entering [child\-dir], expected dev=[n] inode=[n], actual dev=[n] ino=[n], aborting. (\s-1FATAL\s0)" 4.IX Item "previous directory [parent-dir] changed before entering [child-dir], expected dev=[n] inode=[n], actual dev=[n] ino=[n], aborting. (FATAL)"When \f(CW\*(C`rmtree\*(C'\fR returned from deleting files in a child directory, acheck revealed that the parent directory it returned to wasn't the oneit started out from. This is considered a sign of malicious activity..IP "cannot make directory [dir] writeable: [errmsg]" 4.IX Item "cannot make directory [dir] writeable: [errmsg]"Just before removing a directory (after having successfully removedeverything it contained), \f(CW\*(C`rmtree\*(C'\fR attempted to set the permissionson the directory to ensure it could be removed and failed. Programexecution continues, but the directory may possibly not be deleted..IP "cannot remove directory [dir]: [errmsg]" 4.IX Item "cannot remove directory [dir]: [errmsg]"\&\f(CW\*(C`rmtree\*(C'\fR attempted to remove a directory, but failed. This may becausesome objects that were unable to be removed remain in the directory, ora permissions issue. The directory will be left behind..IP "cannot restore permissions of [dir] to [0nnn]: [errmsg]" 4.IX Item "cannot restore permissions of [dir] to [0nnn]: [errmsg]"After having failed to remove a directory, \f(CW\*(C`rmtree\*(C'\fR was unable torestore its permissions from a permissive state back to a possiblymore restrictive setting. (Permissions given in octal)..IP "cannot make file [file] writeable: [errmsg]" 4.IX Item "cannot make file [file] writeable: [errmsg]"\&\f(CW\*(C`rmtree\*(C'\fR attempted to force the permissions of a file to ensure itcould be deleted, but failed to do so. It will, however, still attemptto unlink the file..IP "cannot unlink file [file]: [errmsg]" 4.IX Item "cannot unlink file [file]: [errmsg]"\&\f(CW\*(C`rmtree\*(C'\fR failed to remove a file. Probably a permissions issue..IP "cannot restore permissions of [file] to [0nnn]: [errmsg]" 4.IX Item "cannot restore permissions of [file] to [0nnn]: [errmsg]"After having failed to remove a file, \f(CW\*(C`rmtree\*(C'\fR was also unableto restore the permissions on the file to a possibly less permissivesetting. (Permissions given in octal)..SH "SEE ALSO".IX Header "SEE ALSO".IP "\(bu" 4File::Remove.SpAllows files and directories to be moved to the Trashcan/RecycleBin (where they may later be restored if necessary) if the operatingsystem supports such functionality. This feature may one day bemade available directly in \f(CW\*(C`File::Path\*(C'\fR..IP "\(bu" 4File::Find::Rule.SpWhen removing directory trees, if you want to examine each file todecide whether to delete it (and possibly leaving large swathesalone), \fIFile::Find::Rule\fR offers a convenient and flexible approachto examining directory trees..SH "BUGS".IX Header "BUGS"Please report all bugs on the \s-1RT\s0 queue:.PP<http://rt.cpan.org/NoAuth/Bugs.html?Dist=File\-Path>.SH "ACKNOWLEDGEMENTS".IX Header "ACKNOWLEDGEMENTS"Paul Szabo identified the race condition originally, and BrendanO'Dea wrote an implementation for Debian that addressed the problem.That code was used as a basis for the current code. Their effortsare greatly appreciated..SH "AUTHORS".IX Header "AUTHORS"Tim Bunce <\fITim.Bunce@ig.co.uk\fR> and Charles Bailey<\fIbailey@newman.upenn.edu\fR>. Currently maintained by David Landgren<\fIdavid@landgren.net\fR>..SH "COPYRIGHT".IX Header "COPYRIGHT"This module is copyright (C) Charles Bailey, Tim Bunce andDavid Landgren 1995\-2007.  All rights reserved..SH "LICENSE".IX Header "LICENSE"This library is free software; you can redistribute it and/or modifyit under the same terms as Perl itself.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -