file : add chown, chmod, chgrp support
git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@3003 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
74
file.php
74
file.php
@@ -41,6 +41,80 @@ class file
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Change the group for a file/dir...
|
||||
* @param $filename string The file/directory to change
|
||||
* @param $group mixed The group name or group GID
|
||||
* @throws If filename not exists, or the directory is not RW
|
||||
*/
|
||||
public function chgrp ($filename, $group)
|
||||
{
|
||||
$this->debug (2, "chgrp ($filename, $group)");
|
||||
$filename = $this->realpath ($filename);
|
||||
$this->checkPathRW (dirname ($filename));
|
||||
if (! file_exists ($filename))
|
||||
throw new \Exception (sprintf (dgettext ("domframework",
|
||||
"File '%s' to chmod doesn't exists"),
|
||||
$filename), 404);
|
||||
if (! is_writeable ($filename))
|
||||
throw new \Exception (sprintf (dgettext ("domframework",
|
||||
"File '%s' to chmod is not writeable"),
|
||||
$filename), 500);
|
||||
$rc = chgrp ($filename, $group);
|
||||
$this->debug (1, "chgrp ($filename, $group) => $rc");
|
||||
return $rc;
|
||||
}
|
||||
|
||||
/** Change the rights mode for a file/dir...
|
||||
* @param $filename string The file/directory to change
|
||||
* @throws If filename not exists, or the directory is not RW
|
||||
*/
|
||||
public function chmod ($filename, $mode)
|
||||
{
|
||||
$this->debug (2, "chmod ($filename, $mode)");
|
||||
$filename = $this->realpath ($filename);
|
||||
$this->checkPathRW (dirname ($filename));
|
||||
if (! file_exists ($filename))
|
||||
throw new \Exception (sprintf (dgettext ("domframework",
|
||||
"File '%s' to chmod doesn't exists"),
|
||||
$filename), 404);
|
||||
if (! is_writeable ($filename))
|
||||
throw new \Exception (sprintf (dgettext ("domframework",
|
||||
"File '%s' to chmod is not writeable"),
|
||||
$filename), 500);
|
||||
$rc = chmod ($filename, $mode);
|
||||
$this->debug (1, "chmod ($filename, $mode) => $rc");
|
||||
return $rc;
|
||||
}
|
||||
|
||||
/** Change the owner for a file/dir...
|
||||
* @param $filename string The file/directory to change
|
||||
* @param $user mixed The user name or user UID
|
||||
* @throws If filename not exists, or the directory is not RW
|
||||
*/
|
||||
public function chown ($filename, $user)
|
||||
{
|
||||
$this->debug (2, "chown ($filename, $user)");
|
||||
if (posix_getuid () !== 0 &&
|
||||
posix_getuid () !== $user &&
|
||||
posix_getpwuid (posix_getuid()) !== $user)
|
||||
throw new \Exception (sprintf (dgettext ("domframework",
|
||||
"Only root user can change the file owner for '%s'"),
|
||||
$filename), 500);
|
||||
$filename = $this->realpath ($filename);
|
||||
$this->checkPathRW (dirname ($filename));
|
||||
if (! file_exists ($filename))
|
||||
throw new \Exception (sprintf (dgettext ("domframework",
|
||||
"File '%s' to chmod doesn't exists"),
|
||||
$filename), 404);
|
||||
if (! is_writeable ($filename))
|
||||
throw new \Exception (sprintf (dgettext ("domframework",
|
||||
"File '%s' to chmod is not writeable"),
|
||||
$filename), 500);
|
||||
$rc = chown ($filename, $user);
|
||||
$this->debug (1, "chown ($filename, $user) => $rc");
|
||||
return $rc;
|
||||
}
|
||||
|
||||
/** Chroot in the provided directory
|
||||
* @param $directory string The directory to chroot
|
||||
* @return true if the chroot is done, false if there is a failure
|
||||
|
||||
Reference in New Issue
Block a user