chown example


    public function chown( $file$owner$recursive = false ) {
        if ( ! $this->exists( $file ) ) {
            return false;
        }

        if ( ! $recursive ) {
            return chown( $file$owner );
        }

        if ( ! $this->is_dir( $file ) ) {
            return chown( $file$owner );
        }

        // Is a directory, and we want recursive.         $filelist = $this->dirlist( $file );

        foreach ( $filelist as $filename ) {
            $this->chown( $file . '/' . $filename$owner$recursive );
        }
$chmod = FS_CHMOD_DIR;
        }

        if ( ! ssh2_sftp_mkdir( $this->sftp_link, $path$chmod, true ) ) {
            return false;
        }

        // Set directory permissions.         ssh2_sftp_chmod( $this->sftp_link, $path$chmod );

        if ( $chown ) {
            $this->chown( $path$chown );
        }

        if ( $chgrp ) {
            $this->chgrp( $path$chgrp );
        }

        return true;
    }

    /** * Deletes a directory. * * @since 2.7.0 * * @param string $path Path to directory. * @param bool $recursive Optional. Whether to recursively remove files/directories. * Default false. * @return bool True on success, false on failure. */

    public function chown(string|iterable $files, string|int $user, bool $recursive = false)
    {
        foreach ($this->toIterable($files) as $file) {
            if ($recursive && is_dir($file) && !is_link($file)) {
                $this->chown(new \FilesystemIterator($file)$user, true);
            }
            if (is_link($file) && \function_exists('lchown')) {
                if (!self::box('lchown', $file$user)) {
                    throw new IOException(sprintf('Failed to chown file "%s": ', $file).self::$lastError, 0, null, $file);
                }
            } else {
                if (!self::box('chown', $file$user)) {
                    throw new IOException(sprintf('Failed to chown file "%s": ', $file).self::$lastError, 0, null, $file);
                }
            }
        }
    }
case STREAM_META_TOUCH:
        if (!empty($value)) {
          $return = touch($target$value[0]$value[1]);
        }
        else {
          $return = touch($target);
        }
        break;

      case STREAM_META_OWNER_NAME:
      case STREAM_META_OWNER:
        $return = chown($target$value);
        break;

      case STREAM_META_GROUP_NAME:
      case STREAM_META_GROUP:
        $return = chgrp($target$value);
        break;

      case STREAM_META_ACCESS:
        $return = chmod($target$value);
        break;
    }
    
$this->assertFilePermissions(753, $subdirectory);
    }

    public function testChownByName()
    {
        $this->markAsSkippedIfPosixIsMissing();

        $dir = $this->workspace.\DIRECTORY_SEPARATOR.'dir';
        mkdir($dir);

        $owner = $this->getFileOwner($dir);
        $this->filesystem->chown($dir$owner);

        $this->assertSame($owner$this->getFileOwner($dir));
    }

    public function testChownById()
    {
        $this->markAsSkippedIfPosixIsMissing();

        $dir = $this->workspace.\DIRECTORY_SEPARATOR.'dir';
        mkdir($dir);

        
$v_content = $this->_readBlock();
                                fwrite($v_dest_file$v_content, 512);
                            }
                            if (($v_header['size'] % 512) != 0) {
                                $v_content = $this->_readBlock();
                                fwrite($v_dest_file$v_content($v_header['size'] % 512));
                            }

                            @fclose($v_dest_file);

                            if ($p_preserve) {
                                @chown($v_header['filename']$v_header['uid']);
                                @chgrp($v_header['filename']$v_header['gid']);
                            }

                            // ----- Change the file mode, mtime                             @touch($v_header['filename']$v_header['mtime']);
                            if ($v_header['mode'] & 0111) {
                                // make file executable, obey umask                                 $mode = fileperms($v_header['filename']) | (~umask() & 0111);
                                @chmod($v_header['filename']$mode);
                            }
                        }

                        
Home | Imprint | This part of the site doesn't use cookies.