file : add folding
git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@5425 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
76
file.php
76
file.php
@@ -30,6 +30,7 @@ class file
|
|||||||
* @throws If directory not exists, or the directory is not executable
|
* @throws If directory not exists, or the directory is not executable
|
||||||
*/
|
*/
|
||||||
public function chdir ($directory)
|
public function chdir ($directory)
|
||||||
|
// {{{
|
||||||
{
|
{
|
||||||
$this->debug (2, "chdir ($directory)");
|
$this->debug (2, "chdir ($directory)");
|
||||||
$tmpdirectory = $this->realpath ($directory);
|
$tmpdirectory = $this->realpath ($directory);
|
||||||
@@ -41,6 +42,7 @@ class file
|
|||||||
$this->debug (1, "chdir $directory -> $this->cwd");
|
$this->debug (1, "chdir $directory -> $this->cwd");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
// }}}
|
||||||
|
|
||||||
/** Change the group for a file/dir...
|
/** Change the group for a file/dir...
|
||||||
* @param string $filename The file/directory to change
|
* @param string $filename The file/directory to change
|
||||||
@@ -48,6 +50,7 @@ class file
|
|||||||
* @throws If filename not exists, or the directory is not RW
|
* @throws If filename not exists, or the directory is not RW
|
||||||
*/
|
*/
|
||||||
public function chgrp ($filename, $group)
|
public function chgrp ($filename, $group)
|
||||||
|
// {{{
|
||||||
{
|
{
|
||||||
$this->debug (2, "chgrp ($filename, $group)");
|
$this->debug (2, "chgrp ($filename, $group)");
|
||||||
$filename = $this->realpath ($filename);
|
$filename = $this->realpath ($filename);
|
||||||
@@ -64,6 +67,7 @@ class file
|
|||||||
$this->debug (1, "chgrp ($filename, $group) => $rc");
|
$this->debug (1, "chgrp ($filename, $group) => $rc");
|
||||||
return $rc;
|
return $rc;
|
||||||
}
|
}
|
||||||
|
// }}}
|
||||||
|
|
||||||
/** Change the rights mode for a file/dir...
|
/** Change the rights mode for a file/dir...
|
||||||
* @param string $filename The file/directory to change
|
* @param string $filename The file/directory to change
|
||||||
@@ -71,6 +75,7 @@ class file
|
|||||||
* @throws If filename not exists, or the directory is not RW
|
* @throws If filename not exists, or the directory is not RW
|
||||||
*/
|
*/
|
||||||
public function chmod ($filename, $mode)
|
public function chmod ($filename, $mode)
|
||||||
|
// {{{
|
||||||
{
|
{
|
||||||
$this->debug (2, "chmod ($filename, $mode)");
|
$this->debug (2, "chmod ($filename, $mode)");
|
||||||
$filename = $this->realpath ($filename);
|
$filename = $this->realpath ($filename);
|
||||||
@@ -87,6 +92,7 @@ class file
|
|||||||
$this->debug (1, "chmod ($filename, $mode) => $rc");
|
$this->debug (1, "chmod ($filename, $mode) => $rc");
|
||||||
return $rc;
|
return $rc;
|
||||||
}
|
}
|
||||||
|
// }}}
|
||||||
|
|
||||||
/** Change the owner for a file/dir...
|
/** Change the owner for a file/dir...
|
||||||
* @param string $filename The file/directory to change
|
* @param string $filename The file/directory to change
|
||||||
@@ -94,6 +100,7 @@ class file
|
|||||||
* @throws If filename not exists, or the directory is not RW
|
* @throws If filename not exists, or the directory is not RW
|
||||||
*/
|
*/
|
||||||
public function chown ($filename, $user)
|
public function chown ($filename, $user)
|
||||||
|
// {{{
|
||||||
{
|
{
|
||||||
$this->debug (2, "chown ($filename, $user)");
|
$this->debug (2, "chown ($filename, $user)");
|
||||||
if (posix_getuid () !== 0 &&
|
if (posix_getuid () !== 0 &&
|
||||||
@@ -116,6 +123,7 @@ class file
|
|||||||
$this->debug (1, "chown ($filename, $user) => $rc");
|
$this->debug (1, "chown ($filename, $user) => $rc");
|
||||||
return $rc;
|
return $rc;
|
||||||
}
|
}
|
||||||
|
// }}}
|
||||||
|
|
||||||
/** Chroot in the provided directory
|
/** Chroot in the provided directory
|
||||||
* @param string $directory The directory to chroot
|
* @param string $directory The directory to chroot
|
||||||
@@ -123,6 +131,7 @@ class file
|
|||||||
* @throws If directory not exists, or the directory is not executable
|
* @throws If directory not exists, or the directory is not executable
|
||||||
*/
|
*/
|
||||||
public function chroot ($directory)
|
public function chroot ($directory)
|
||||||
|
// {{{
|
||||||
{
|
{
|
||||||
// Use the checkPathRO (using the $this->baseDir) to not allow to go away of
|
// Use the checkPathRO (using the $this->baseDir) to not allow to go away of
|
||||||
// the chroot.
|
// the chroot.
|
||||||
@@ -134,6 +143,7 @@ class file
|
|||||||
$this->debug (1, "chroot $directory -> $this->baseDir");
|
$this->debug (1, "chroot $directory -> $this->baseDir");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
// }}}
|
||||||
|
|
||||||
/** Checks whether a file or directory exists
|
/** Checks whether a file or directory exists
|
||||||
* @param string $filename The file or directory to verify
|
* @param string $filename The file or directory to verify
|
||||||
@@ -141,6 +151,7 @@ class file
|
|||||||
* @throws If parent directory not exists, or is not executable
|
* @throws If parent directory not exists, or is not executable
|
||||||
*/
|
*/
|
||||||
public function file_exists ($filename)
|
public function file_exists ($filename)
|
||||||
|
// {{{
|
||||||
{
|
{
|
||||||
$this->debug (2, "file_exists ($filename)");
|
$this->debug (2, "file_exists ($filename)");
|
||||||
$filename = $this->realpath ($filename);
|
$filename = $this->realpath ($filename);
|
||||||
@@ -157,6 +168,7 @@ class file
|
|||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
// }}}
|
||||||
|
|
||||||
/** Get the file contents
|
/** Get the file contents
|
||||||
* @param string $filename Name of the file to read
|
* @param string $filename Name of the file to read
|
||||||
@@ -165,6 +177,7 @@ class file
|
|||||||
* exists or is not readable
|
* exists or is not readable
|
||||||
*/
|
*/
|
||||||
public function file_get_contents ($filename)
|
public function file_get_contents ($filename)
|
||||||
|
// {{{
|
||||||
{
|
{
|
||||||
$this->debug (2, "file_get_contents ($filename)");
|
$this->debug (2, "file_get_contents ($filename)");
|
||||||
$filename = $this->realpath ($filename);
|
$filename = $this->realpath ($filename);
|
||||||
@@ -182,6 +195,7 @@ class file
|
|||||||
" bytes");
|
" bytes");
|
||||||
return $contents;
|
return $contents;
|
||||||
}
|
}
|
||||||
|
// }}}
|
||||||
|
|
||||||
/** Write a string to a file
|
/** Write a string to a file
|
||||||
* @param string $filename Path to the file where to write the data
|
* @param string $filename Path to the file where to write the data
|
||||||
@@ -192,6 +206,7 @@ class file
|
|||||||
* exists and is not writeable
|
* exists and is not writeable
|
||||||
*/
|
*/
|
||||||
public function file_put_contents ($filename, $data, $flags=0)
|
public function file_put_contents ($filename, $data, $flags=0)
|
||||||
|
// {{{
|
||||||
{
|
{
|
||||||
$this->debug (2, "file_put_contents ($filename)");
|
$this->debug (2, "file_put_contents ($filename)");
|
||||||
$filename = $this->realpath ($filename);
|
$filename = $this->realpath ($filename);
|
||||||
@@ -210,6 +225,7 @@ class file
|
|||||||
return $contents;
|
return $contents;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
// }}}
|
||||||
|
|
||||||
/** Get the file modification time of a file
|
/** Get the file modification time of a file
|
||||||
* @param string $filename Path to the file
|
* @param string $filename Path to the file
|
||||||
@@ -219,12 +235,14 @@ class file
|
|||||||
* @throws If parent directory not exists, is not writeable
|
* @throws If parent directory not exists, is not writeable
|
||||||
*/
|
*/
|
||||||
public function filemtime ($filename)
|
public function filemtime ($filename)
|
||||||
|
// {{{
|
||||||
{
|
{
|
||||||
$this->debug (2, "filemtime ($filename)");
|
$this->debug (2, "filemtime ($filename)");
|
||||||
$filename = $this->realpath ($filename);
|
$filename = $this->realpath ($filename);
|
||||||
$this->checkPathRO (dirname ($filename));
|
$this->checkPathRO (dirname ($filename));
|
||||||
return filemtime ($filename);
|
return filemtime ($filename);
|
||||||
}
|
}
|
||||||
|
// }}}
|
||||||
|
|
||||||
/** Get the file size
|
/** Get the file size
|
||||||
* @param string $filename Path to the file
|
* @param string $filename Path to the file
|
||||||
@@ -232,12 +250,14 @@ class file
|
|||||||
* @throws If parent directory not exists, is not writeable
|
* @throws If parent directory not exists, is not writeable
|
||||||
*/
|
*/
|
||||||
public function filesize ($filename)
|
public function filesize ($filename)
|
||||||
|
// {{{
|
||||||
{
|
{
|
||||||
$this->debug (2, "filesize ($filename)");
|
$this->debug (2, "filesize ($filename)");
|
||||||
$filename = $this->realpath ($filename);
|
$filename = $this->realpath ($filename);
|
||||||
$this->checkPathRO (dirname ($filename));
|
$this->checkPathRO (dirname ($filename));
|
||||||
return filesize ($filename);
|
return filesize ($filename);
|
||||||
}
|
}
|
||||||
|
// }}}
|
||||||
|
|
||||||
/** Get the file info of the provided filename
|
/** Get the file info of the provided filename
|
||||||
* @param string $filename Path to the file
|
* @param string $filename Path to the file
|
||||||
@@ -245,6 +265,7 @@ class file
|
|||||||
* @throws If parent directory not exists, is not writeable
|
* @throws If parent directory not exists, is not writeable
|
||||||
*/
|
*/
|
||||||
public function fileinfoMimeType ($filename)
|
public function fileinfoMimeType ($filename)
|
||||||
|
// {{{
|
||||||
{
|
{
|
||||||
$this->debug (2, "filesize ($filename)");
|
$this->debug (2, "filesize ($filename)");
|
||||||
$filename = $this->realpath ($filename);
|
$filename = $this->realpath ($filename);
|
||||||
@@ -252,14 +273,17 @@ class file
|
|||||||
$finfo = new \finfo (FILEINFO_MIME_TYPE);
|
$finfo = new \finfo (FILEINFO_MIME_TYPE);
|
||||||
return $finfo->file ($filename);
|
return $finfo->file ($filename);
|
||||||
}
|
}
|
||||||
|
// }}}
|
||||||
|
|
||||||
/** Return the current working directory
|
/** Return the current working directory
|
||||||
* @return string the current working directory */
|
* @return string the current working directory */
|
||||||
public function getcwd ()
|
public function getcwd ()
|
||||||
|
// {{{
|
||||||
{
|
{
|
||||||
$this->debug (1, "getcwd $this->cwd");
|
$this->debug (1, "getcwd $this->cwd");
|
||||||
return $this->cwd;
|
return $this->cwd;
|
||||||
}
|
}
|
||||||
|
// }}}
|
||||||
|
|
||||||
/** Find pathnames matching a pattern
|
/** Find pathnames matching a pattern
|
||||||
* If there is some unreadable files, skip them quietly
|
* If there is some unreadable files, skip them quietly
|
||||||
@@ -270,6 +294,7 @@ class file
|
|||||||
* or if there is one file unreadable
|
* or if there is one file unreadable
|
||||||
*/
|
*/
|
||||||
public function glob ($pattern, $flags=0)
|
public function glob ($pattern, $flags=0)
|
||||||
|
// {{{
|
||||||
{
|
{
|
||||||
$this->debug (2, "glob ($pattern, $flags)");
|
$this->debug (2, "glob ($pattern, $flags)");
|
||||||
$this->checkPathRO ($this->baseDir);
|
$this->checkPathRO ($this->baseDir);
|
||||||
@@ -299,6 +324,7 @@ class file
|
|||||||
}
|
}
|
||||||
return $files;
|
return $files;
|
||||||
}
|
}
|
||||||
|
// }}}
|
||||||
|
|
||||||
/** Tells whether the given filename is a directory
|
/** Tells whether the given filename is a directory
|
||||||
* @param string $filename The filename to test
|
* @param string $filename The filename to test
|
||||||
@@ -307,6 +333,7 @@ class file
|
|||||||
* @throws If parent directory not exists, or is not executable
|
* @throws If parent directory not exists, or is not executable
|
||||||
*/
|
*/
|
||||||
public function is_dir ($filename)
|
public function is_dir ($filename)
|
||||||
|
// {{{
|
||||||
{
|
{
|
||||||
$this->debug (2, "is_dir ($filename)");
|
$this->debug (2, "is_dir ($filename)");
|
||||||
$filename = $this->realpath ($filename);
|
$filename = $this->realpath ($filename);
|
||||||
@@ -315,6 +342,7 @@ class file
|
|||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
// }}}
|
||||||
|
|
||||||
/** Tells whether the given filename is a valid file
|
/** Tells whether the given filename is a valid file
|
||||||
* @param string $filename The filename to test
|
* @param string $filename The filename to test
|
||||||
@@ -322,6 +350,7 @@ class file
|
|||||||
* @throws If parent directory not exists, or is not executable
|
* @throws If parent directory not exists, or is not executable
|
||||||
*/
|
*/
|
||||||
public function is_file ($filename)
|
public function is_file ($filename)
|
||||||
|
// {{{
|
||||||
{
|
{
|
||||||
$this->debug (2, "is_file ($filename)");
|
$this->debug (2, "is_file ($filename)");
|
||||||
$filename = $this->realpath ($filename);
|
$filename = $this->realpath ($filename);
|
||||||
@@ -330,6 +359,7 @@ class file
|
|||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
// }}}
|
||||||
|
|
||||||
/** Tells whether a file exists and is executable
|
/** Tells whether a file exists and is executable
|
||||||
* @param string $filename The filename to test
|
* @param string $filename The filename to test
|
||||||
@@ -337,6 +367,7 @@ class file
|
|||||||
* @throws If parent directory not exists, or is not executable
|
* @throws If parent directory not exists, or is not executable
|
||||||
*/
|
*/
|
||||||
public function is_executable ($filename)
|
public function is_executable ($filename)
|
||||||
|
// {{{
|
||||||
{
|
{
|
||||||
$this->debug (2, "is_executable ($filename)");
|
$this->debug (2, "is_executable ($filename)");
|
||||||
$filename = $this->realpath ($filename);
|
$filename = $this->realpath ($filename);
|
||||||
@@ -345,6 +376,7 @@ class file
|
|||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
// }}}
|
||||||
|
|
||||||
/** Tells whether a file exists and is readable
|
/** Tells whether a file exists and is readable
|
||||||
* @param string $filename The filename to test
|
* @param string $filename The filename to test
|
||||||
@@ -352,6 +384,7 @@ class file
|
|||||||
* @throws If parent directory not exists, or is not executable
|
* @throws If parent directory not exists, or is not executable
|
||||||
*/
|
*/
|
||||||
public function is_readable ($filename)
|
public function is_readable ($filename)
|
||||||
|
// {{{
|
||||||
{
|
{
|
||||||
$this->debug (2, "is_readable ($filename)");
|
$this->debug (2, "is_readable ($filename)");
|
||||||
$filename = $this->realpath ($filename);
|
$filename = $this->realpath ($filename);
|
||||||
@@ -360,6 +393,7 @@ class file
|
|||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
// }}}
|
||||||
|
|
||||||
/** Tells whether a file exists and is writeable
|
/** Tells whether a file exists and is writeable
|
||||||
* @param string $filename The filename to test
|
* @param string $filename The filename to test
|
||||||
@@ -367,6 +401,7 @@ class file
|
|||||||
* @throws If parent directory not exists, or is not executable
|
* @throws If parent directory not exists, or is not executable
|
||||||
*/
|
*/
|
||||||
public function is_writeable ($filename)
|
public function is_writeable ($filename)
|
||||||
|
// {{{
|
||||||
{
|
{
|
||||||
$this->debug (2, "is_writeable ($filename)");
|
$this->debug (2, "is_writeable ($filename)");
|
||||||
$filename = $this->realpath ($filename);
|
$filename = $this->realpath ($filename);
|
||||||
@@ -375,6 +410,7 @@ class file
|
|||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
// }}}
|
||||||
|
|
||||||
/** Lock a file exclusively
|
/** Lock a file exclusively
|
||||||
* @param string $filename The file to lock
|
* @param string $filename The file to lock
|
||||||
@@ -382,6 +418,7 @@ class file
|
|||||||
* @throws If parent directory not exists, or is not writeable
|
* @throws If parent directory not exists, or is not writeable
|
||||||
*/
|
*/
|
||||||
public function lockEX ($filename)
|
public function lockEX ($filename)
|
||||||
|
// {{{
|
||||||
{
|
{
|
||||||
$this->debug (2, "lockEX ($filename)");
|
$this->debug (2, "lockEX ($filename)");
|
||||||
$filename = $this->realpath ($filename);
|
$filename = $this->realpath ($filename);
|
||||||
@@ -397,6 +434,7 @@ class file
|
|||||||
$this->locks[$filename] = fopen ($filename, "rt");
|
$this->locks[$filename] = fopen ($filename, "rt");
|
||||||
return flock ($this->locks[$filename], LOCK_EX);
|
return flock ($this->locks[$filename], LOCK_EX);
|
||||||
}
|
}
|
||||||
|
// }}}
|
||||||
|
|
||||||
/** Lock a file shared (allow multiple read)
|
/** Lock a file shared (allow multiple read)
|
||||||
* @param string $filename The file to lock
|
* @param string $filename The file to lock
|
||||||
@@ -404,6 +442,7 @@ class file
|
|||||||
* @throws If parent directory not exists, or is not writeable
|
* @throws If parent directory not exists, or is not writeable
|
||||||
*/
|
*/
|
||||||
public function lockSH ($filename)
|
public function lockSH ($filename)
|
||||||
|
// {{{
|
||||||
{
|
{
|
||||||
$this->debug (2, "lockSH ($filename)");
|
$this->debug (2, "lockSH ($filename)");
|
||||||
$filename = $this->realpath ($filename);
|
$filename = $this->realpath ($filename);
|
||||||
@@ -419,6 +458,7 @@ class file
|
|||||||
$this->locks[$filename] = fopen ($filename, "rt");
|
$this->locks[$filename] = fopen ($filename, "rt");
|
||||||
return flock ($this->locks[$filename], LOCK_SH);
|
return flock ($this->locks[$filename], LOCK_SH);
|
||||||
}
|
}
|
||||||
|
// }}}
|
||||||
|
|
||||||
/** Unlock a file previously locked
|
/** Unlock a file previously locked
|
||||||
* @param string $filename The file to lock
|
* @param string $filename The file to lock
|
||||||
@@ -426,6 +466,7 @@ class file
|
|||||||
* @throws If parent directory not exists, or is not writeable
|
* @throws If parent directory not exists, or is not writeable
|
||||||
*/
|
*/
|
||||||
public function lockUN ($filename)
|
public function lockUN ($filename)
|
||||||
|
// {{{
|
||||||
{
|
{
|
||||||
$this->debug (2, "lockUN ($filename)");
|
$this->debug (2, "lockUN ($filename)");
|
||||||
$filename = $this->realpath ($filename);
|
$filename = $this->realpath ($filename);
|
||||||
@@ -438,6 +479,7 @@ class file
|
|||||||
}
|
}
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
// }}}
|
||||||
|
|
||||||
/** Calculate the md5 sum of a file
|
/** Calculate the md5 sum of a file
|
||||||
* @param string $filename The file to hash
|
* @param string $filename The file to hash
|
||||||
@@ -445,6 +487,7 @@ class file
|
|||||||
* @throws If the file doesn't exists
|
* @throws If the file doesn't exists
|
||||||
*/
|
*/
|
||||||
public function md5_file ($filename)
|
public function md5_file ($filename)
|
||||||
|
// {{{
|
||||||
{
|
{
|
||||||
$this->debug (2, "md5_file ($filename)");
|
$this->debug (2, "md5_file ($filename)");
|
||||||
$filename = $this->realpath ($filename);
|
$filename = $this->realpath ($filename);
|
||||||
@@ -459,6 +502,7 @@ class file
|
|||||||
$filename), 500);
|
$filename), 500);
|
||||||
return md5_file ($filename);
|
return md5_file ($filename);
|
||||||
}
|
}
|
||||||
|
// }}}
|
||||||
|
|
||||||
/** Create a new directory
|
/** Create a new directory
|
||||||
* @param string $pathname The directory to create
|
* @param string $pathname The directory to create
|
||||||
@@ -469,6 +513,7 @@ class file
|
|||||||
* @throws If parent directory not exists, is not writeable
|
* @throws If parent directory not exists, is not writeable
|
||||||
*/
|
*/
|
||||||
public function mkdir ($pathname, $mode = 0777, $recursive = false)
|
public function mkdir ($pathname, $mode = 0777, $recursive = false)
|
||||||
|
// {{{
|
||||||
{
|
{
|
||||||
$this->debug (2, "mkdir ($pathname, $mode, $recursive)");
|
$this->debug (2, "mkdir ($pathname, $mode, $recursive)");
|
||||||
$pathname = $this->realpath ($pathname);
|
$pathname = $this->realpath ($pathname);
|
||||||
@@ -506,6 +551,7 @@ class file
|
|||||||
$this->debug (1, "mkdir ($pathname, $mode, $recursive) => $rc");
|
$this->debug (1, "mkdir ($pathname, $mode, $recursive) => $rc");
|
||||||
return $rc;
|
return $rc;
|
||||||
}
|
}
|
||||||
|
// }}}
|
||||||
|
|
||||||
/** Copy a file or a directory
|
/** Copy a file or a directory
|
||||||
* @param string $oldname The file to copy
|
* @param string $oldname The file to copy
|
||||||
@@ -514,6 +560,7 @@ class file
|
|||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function copy ($oldname, $newname)
|
public function copy ($oldname, $newname)
|
||||||
|
// {{{
|
||||||
{
|
{
|
||||||
$this->debug (2, "copy ($oldname, $newname)");
|
$this->debug (2, "copy ($oldname, $newname)");
|
||||||
$oldname = $this->realpath ($oldname);
|
$oldname = $this->realpath ($oldname);
|
||||||
@@ -536,6 +583,7 @@ class file
|
|||||||
$this->debug (1, "copy ($oldname, $newname) => $rc");
|
$this->debug (1, "copy ($oldname, $newname) => $rc");
|
||||||
return $rc;
|
return $rc;
|
||||||
}
|
}
|
||||||
|
// }}}
|
||||||
|
|
||||||
/** Renames a file or directory
|
/** Renames a file or directory
|
||||||
* @param string $oldname The file or directory to rename
|
* @param string $oldname The file or directory to rename
|
||||||
@@ -544,6 +592,7 @@ class file
|
|||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function rename ($oldname, $newname)
|
public function rename ($oldname, $newname)
|
||||||
|
// {{{
|
||||||
{
|
{
|
||||||
$this->debug (2, "rename ($oldname, $newname)");
|
$this->debug (2, "rename ($oldname, $newname)");
|
||||||
$oldname = $this->realpath ($oldname);
|
$oldname = $this->realpath ($oldname);
|
||||||
@@ -554,6 +603,7 @@ class file
|
|||||||
$this->debug (1, "rename ($oldname, $newname) => $rc");
|
$this->debug (1, "rename ($oldname, $newname) => $rc");
|
||||||
return $rc;
|
return $rc;
|
||||||
}
|
}
|
||||||
|
// }}}
|
||||||
|
|
||||||
/** Return a ini file converted to an array
|
/** Return a ini file converted to an array
|
||||||
* @param string $filename The filename of the ini file being parsed.
|
* @param string $filename The filename of the ini file being parsed.
|
||||||
@@ -561,6 +611,7 @@ class file
|
|||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function parse_ini_file ($filename, $process_sections = false)
|
public function parse_ini_file ($filename, $process_sections = false)
|
||||||
|
// {{{
|
||||||
{
|
{
|
||||||
$this->debug (2, "parse_ini_file ($filename, $process_sections)");
|
$this->debug (2, "parse_ini_file ($filename, $process_sections)");
|
||||||
$filename = $this->realpath ($filename);
|
$filename = $this->realpath ($filename);
|
||||||
@@ -575,6 +626,7 @@ class file
|
|||||||
$filename), 500);
|
$filename), 500);
|
||||||
return parse_ini_file ($filename, $process_sections);
|
return parse_ini_file ($filename, $process_sections);
|
||||||
}
|
}
|
||||||
|
// }}}
|
||||||
|
|
||||||
/** Return the canonical absolute path. Do not check if the directory exists,
|
/** Return the canonical absolute path. Do not check if the directory exists,
|
||||||
* if there is links. Just calculate the realpath based on the chroot value
|
* if there is links. Just calculate the realpath based on the chroot value
|
||||||
@@ -582,6 +634,7 @@ class file
|
|||||||
* @return string the canonical absolute path
|
* @return string the canonical absolute path
|
||||||
*/
|
*/
|
||||||
public function realpath ($path)
|
public function realpath ($path)
|
||||||
|
// {{{
|
||||||
{
|
{
|
||||||
$oriPath = $path;
|
$oriPath = $path;
|
||||||
$this->debug (2, "realpath ($oriPath)");
|
$this->debug (2, "realpath ($oriPath)");
|
||||||
@@ -620,6 +673,7 @@ class file
|
|||||||
$this->debug (1, "realpath ($oriPath) => $path");
|
$this->debug (1, "realpath ($oriPath) => $path");
|
||||||
return $path;
|
return $path;
|
||||||
}
|
}
|
||||||
|
// }}}
|
||||||
|
|
||||||
/** Remove the provided directory
|
/** Remove the provided directory
|
||||||
* If the recurse flag is true, remove the content too (files and
|
* If the recurse flag is true, remove the content too (files and
|
||||||
@@ -631,6 +685,7 @@ class file
|
|||||||
* dir is not writeable
|
* dir is not writeable
|
||||||
*/
|
*/
|
||||||
public function rmdir ($dirname, $recursive=false)
|
public function rmdir ($dirname, $recursive=false)
|
||||||
|
// {{{
|
||||||
{
|
{
|
||||||
$this->debug (2, "rmdir ($dirname, $recursive)");
|
$this->debug (2, "rmdir ($dirname, $recursive)");
|
||||||
$tmpdirname = $this->realpath ($dirname);
|
$tmpdirname = $this->realpath ($dirname);
|
||||||
@@ -652,6 +707,7 @@ class file
|
|||||||
}
|
}
|
||||||
return rmdir ($tmpdirname);
|
return rmdir ($tmpdirname);
|
||||||
}
|
}
|
||||||
|
// }}}
|
||||||
|
|
||||||
/** Return the list of files and directories in the directory.
|
/** Return the list of files and directories in the directory.
|
||||||
* Do not return the . and .. virtual dirs.
|
* Do not return the . and .. virtual dirs.
|
||||||
@@ -661,6 +717,7 @@ class file
|
|||||||
* @throws If directory not exists, or is not executable
|
* @throws If directory not exists, or is not executable
|
||||||
*/
|
*/
|
||||||
public function scandir ($directory)
|
public function scandir ($directory)
|
||||||
|
// {{{
|
||||||
{
|
{
|
||||||
$this->debug (2, "scandir ($directory)");
|
$this->debug (2, "scandir ($directory)");
|
||||||
$directory = $this->realpath ($directory);
|
$directory = $this->realpath ($directory);
|
||||||
@@ -669,6 +726,7 @@ class file
|
|||||||
natsort ($res);
|
natsort ($res);
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
// }}}
|
||||||
|
|
||||||
/** Return the list of files and directories in the directory.
|
/** Return the list of files and directories in the directory.
|
||||||
* Do not return the . and .. virtual dirs.
|
* Do not return the . and .. virtual dirs.
|
||||||
@@ -678,6 +736,7 @@ class file
|
|||||||
* @throws If directory not exists, or is not executable
|
* @throws If directory not exists, or is not executable
|
||||||
*/
|
*/
|
||||||
public function scandirNotSorted ($directory)
|
public function scandirNotSorted ($directory)
|
||||||
|
// {{{
|
||||||
{
|
{
|
||||||
$this->debug (2, "scandirNotSorted ($directory)");
|
$this->debug (2, "scandirNotSorted ($directory)");
|
||||||
$directory = $this->realpath ($directory);
|
$directory = $this->realpath ($directory);
|
||||||
@@ -686,6 +745,7 @@ class file
|
|||||||
array('..', '.')));
|
array('..', '.')));
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
// }}}
|
||||||
|
|
||||||
/** Calculate the sha1 sum of a file
|
/** Calculate the sha1 sum of a file
|
||||||
* @param string $filename The file to hash
|
* @param string $filename The file to hash
|
||||||
@@ -693,6 +753,7 @@ class file
|
|||||||
* @throws If the file doesn't exists
|
* @throws If the file doesn't exists
|
||||||
*/
|
*/
|
||||||
public function sha1_file ($filename)
|
public function sha1_file ($filename)
|
||||||
|
// {{{
|
||||||
{
|
{
|
||||||
$this->debug (2, "sha1_file ($filename)");
|
$this->debug (2, "sha1_file ($filename)");
|
||||||
$filename = $this->realpath ($filename);
|
$filename = $this->realpath ($filename);
|
||||||
@@ -707,6 +768,7 @@ class file
|
|||||||
$filename), 500);
|
$filename), 500);
|
||||||
return sha1_file ($filename);
|
return sha1_file ($filename);
|
||||||
}
|
}
|
||||||
|
// }}}
|
||||||
|
|
||||||
/** Create a new file or update the timestamp if the file exists
|
/** Create a new file or update the timestamp if the file exists
|
||||||
* @param string $filename the filename
|
* @param string $filename the filename
|
||||||
@@ -718,6 +780,7 @@ class file
|
|||||||
* @throws If parent directory not exists, is not writeable
|
* @throws If parent directory not exists, is not writeable
|
||||||
*/
|
*/
|
||||||
public function touch ($filename, $time = null, $atime = null)
|
public function touch ($filename, $time = null, $atime = null)
|
||||||
|
// {{{
|
||||||
{
|
{
|
||||||
$this->debug (2, "touch ($filename, $time, $atime)");
|
$this->debug (2, "touch ($filename, $time, $atime)");
|
||||||
$filename = $this->realpath ($filename);
|
$filename = $this->realpath ($filename);
|
||||||
@@ -730,6 +793,7 @@ class file
|
|||||||
$this->debug (1, "touch ($filename, $time, $atime) => $rc");
|
$this->debug (1, "touch ($filename, $time, $atime) => $rc");
|
||||||
return $rc;
|
return $rc;
|
||||||
}
|
}
|
||||||
|
// }}}
|
||||||
|
|
||||||
/** Delete an existing file.
|
/** Delete an existing file.
|
||||||
* @param string $filename The filename to remove
|
* @param string $filename The filename to remove
|
||||||
@@ -737,6 +801,7 @@ class file
|
|||||||
* @throws If parent directory not exists, or is not executable
|
* @throws If parent directory not exists, or is not executable
|
||||||
*/
|
*/
|
||||||
public function unlink ($filename)
|
public function unlink ($filename)
|
||||||
|
// {{{
|
||||||
{
|
{
|
||||||
$this->debug (2, "unlink ($filename)");
|
$this->debug (2, "unlink ($filename)");
|
||||||
$filename = $this->realpath ($filename);
|
$filename = $this->realpath ($filename);
|
||||||
@@ -745,6 +810,7 @@ class file
|
|||||||
return false;
|
return false;
|
||||||
return unlink ($filename);
|
return unlink ($filename);
|
||||||
}
|
}
|
||||||
|
// }}}
|
||||||
|
|
||||||
/** Check all the parents of the $directory if they are available, and
|
/** Check all the parents of the $directory if they are available, and
|
||||||
* executable. The path must exists.
|
* executable. The path must exists.
|
||||||
@@ -756,6 +822,7 @@ class file
|
|||||||
* @throws if there is a missing part, or a parent is not executable
|
* @throws if there is a missing part, or a parent is not executable
|
||||||
*/
|
*/
|
||||||
private function checkPathRO ($path)
|
private function checkPathRO ($path)
|
||||||
|
// {{{
|
||||||
{
|
{
|
||||||
$this->debug (2, "checkPathRO ($path)");
|
$this->debug (2, "checkPathRO ($path)");
|
||||||
$path = preg_replace ("#//+#", "/", $path);
|
$path = preg_replace ("#//+#", "/", $path);
|
||||||
@@ -826,6 +893,7 @@ class file
|
|||||||
}
|
}
|
||||||
return $this->checkExternalPathRO ($path);
|
return $this->checkExternalPathRO ($path);
|
||||||
}
|
}
|
||||||
|
// }}}
|
||||||
|
|
||||||
/** Check all the parents of the $directory if they are available, and
|
/** Check all the parents of the $directory if they are available, and
|
||||||
* executable. The path must exists.
|
* executable. The path must exists.
|
||||||
@@ -837,6 +905,7 @@ class file
|
|||||||
* @throws if there is a missing part, or a parent is not executable
|
* @throws if there is a missing part, or a parent is not executable
|
||||||
*/
|
*/
|
||||||
private function checkPathRW ($path)
|
private function checkPathRW ($path)
|
||||||
|
// {{{
|
||||||
{
|
{
|
||||||
$this->debug (2, "checkPathRW ($path)");
|
$this->debug (2, "checkPathRW ($path)");
|
||||||
$this->checkPathRO ($path);
|
$this->checkPathRO ($path);
|
||||||
@@ -860,6 +929,7 @@ class file
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
// }}}
|
||||||
|
|
||||||
/** Save a debug log
|
/** Save a debug log
|
||||||
* @param integer $prio The message priority. Should be higher than
|
* @param integer $prio The message priority. Should be higher than
|
||||||
@@ -868,6 +938,7 @@ class file
|
|||||||
* @return null;
|
* @return null;
|
||||||
*/
|
*/
|
||||||
private function debug ($prio, $message)
|
private function debug ($prio, $message)
|
||||||
|
// {{{
|
||||||
{
|
{
|
||||||
if ($this->debug === false || $this->debug === 0)
|
if ($this->debug === false || $this->debug === 0)
|
||||||
return;
|
return;
|
||||||
@@ -879,6 +950,7 @@ class file
|
|||||||
// FILE_APPEND);
|
// FILE_APPEND);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// }}}
|
||||||
|
|
||||||
/** External function allowed to be overloaded to test the RO access to a
|
/** External function allowed to be overloaded to test the RO access to a
|
||||||
* resource
|
* resource
|
||||||
@@ -886,9 +958,11 @@ class file
|
|||||||
* @return boolean true if RO access, false if not
|
* @return boolean true if RO access, false if not
|
||||||
*/
|
*/
|
||||||
public function checkExternalPathRO ($path)
|
public function checkExternalPathRO ($path)
|
||||||
|
// {{{
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
// }}}
|
||||||
|
|
||||||
/** External function allowed to be overloaded to test the RW access to a
|
/** External function allowed to be overloaded to test the RW access to a
|
||||||
* resource
|
* resource
|
||||||
@@ -896,7 +970,9 @@ class file
|
|||||||
* @return boolean true if RW access, false if not
|
* @return boolean true if RW access, false if not
|
||||||
*/
|
*/
|
||||||
public function checkExternalPathRW ($path)
|
public function checkExternalPathRW ($path)
|
||||||
|
// {{{
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
// }}}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user