Determine whether the user has write access to the file. This checks the
S_IWUSR flag is set in permissions.

@return boolean
@throws SftpStatusException
@throws SshException
426975
public boolean canWrite() throws SftpStatusException, SshException {
		// This is long hand because gcj chokes when it is not? Investigate why
		if ((getAttributes().getPermissions().longValue() & SftpFileAttributes.S_IWUSR) == SftpFileAttributes.S_IWUSR
				|| (getAttributes().getPermissions().longValue() & SftpFileAttributes.S_IWGRP) == SftpFileAttributes.S_IWGRP
				|| (getAttributes().getPermissions().longValue() & SftpFileAttributes.S_IWOTH) == SftpFileAttributes.S_IWOTH) {
			return true;
		}
		return false;
	}
41971
protected function hasCorrectPermissionForUpdate() : bool
    {
        if (! $this->pathToUpdate) {
            throw new \Exception('No directory set for update. Please set the update with: setPathToUpdate(path).');
        }

        $collection = collect($this->pathToUpdate->files())->each(function ($file) { /* @var \SplFileInfo $file */
            if (! File::isWritable($file->getRealPath())) {
                event(new HasWrongPermissions($this));

                return false;
            }
        });

        return true;
    }
170419
protected boolean isPermissionDenied(List<String> output){
        return output.stream().anyMatch(s -> s != null && s.contains(PERMISSION_DENIED_MESSAGE));
    }
1148030
public function isAlive(): bool
    {
        if (false === static::$testingEnabled) {
            return false !== fsockopen($this->getHost(), $this->getPort());
        }

        return static::$testingServiceIsUp;
    }
157071
@Override
    public boolean requestPermissionToWrite() {
        boolean rc = false;
        synchronized (this) {
            if ((currentState & WRITE_NOT_ALLOWED_MASK) == 0) {
                currentState = (currentState | WRITE_PENDING) & WRITE_PENDING_CLEAR_OUT;
                rc = true;
            }
        }
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            Tr.debug(tc, "requestPermissionToWrite returning " + rc);
        }
        return rc;
    }
931231
public static function canAutoUpdate()
    {
        if (!is_writable(PIWIK_INCLUDE_PATH . '/') ||
            !is_writable(PIWIK_DOCUMENT_ROOT . '/index.php') ||
            !is_writable(PIWIK_INCLUDE_PATH . '/core') ||
            !is_writable(PIWIK_USER_PATH . '/config/global.ini.php')
        ) {
            return false;
        }
        return true;
    }
1186498
public SftpFileAttributes getAttributes() throws SftpStatusException,
			SshException {
		if (attrs == null) {
			attrs = sftp.getAttributes(getAbsolutePath());
		}

		return attrs;
	}
705734
private static boolean isSharedFileLockTable() {
        if (!propertyChecked) {
            synchronized (FileChannelImpl.class) {
                if (!propertyChecked) {
                    /*
                    String value = AccessController.doPrivileged(
                        new GetPropertyAction(
                            "sun.nio.ch.disableSystemWideOverlappingFileLockCheck"));
                    */
                    String value =
                        System.getProperty("sun.nio.ch.disableSystemWideOverlappingFileLockCheck");
                    isSharedFileLockTable = ((value == null) || value.equals("false"));
                    propertyChecked = true;
                }
            }
        }
        return isSharedFileLockTable;
    }
1340419
def is_file_writable(test_file):
    
    p = Path(test_file)

    if p.is_symlink():
        p = p.resolve(strict=False)

    # p.is_file() throws an exception in some cases
    if p.exists() and p.is_file():
        return os.access(
            os.fspath(p),
            os.W_OK,
            effective_ids=(os.access in os.supports_effective_ids),
        )
    else:
        try:
            fp = p.open('wb')
        except OSError:
            return False
        else:
            fp.close()
            with suppress(OSError):
                p.unlink()
        return True
1301921
public void changePermissions(String filename, String permissions)
			throws SftpStatusException, SshException {

		SftpFileAttributes attrs = new SftpFileAttributes(this,
				SftpFileAttributes.SSH_FILEXFER_TYPE_UNKNOWN);
		attrs.setPermissions(permissions);
		setAttributes(filename, attrs);

	}
47526
public void cdup() throws SftpStatusException, SshException {

		SftpFile cd = sftp.getFile(cwd);

		SftpFile parent = cd.getParent();

		if (parent != null)
			cwd = parent.getAbsolutePath();

	}
914196
public function lock()
    {
        if (!$this->isLocked()) {
            $file = fopen($this->getFilePath(), 'w');
            if ($file) {
                fwrite($file, getmypid());
                fclose($file);
                return true;
            }
        }
        return false;
    }
575863
public static function save()
	{
		self::lock();
		if ( is_null( self::$authFileP ) ) throw new Exception( 'No lock has been requested' );

		$file = '<?php if (realpath(__FILE__)===realpath($_SERVER["SCRIPT_FILENAME"])) {header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found");die();}?>' . "\n";
		$file.= json_encode( self::$auth );

		self::write( $file );

		return true;
	}
1208041
protected function _checkPermissions()
    {
        if($this->_allowedHostnames === NULL)
            return;

        if(key_exists('REMOTE_HOST', $_SERVER))
            $host = $_SERVER['REMOTE_HOST'];
        else
            $host = $_SERVER['REMOTE_ADDR'];

        if(!in_array($host, $this->_allowedHostnames))
            throw new Exception("Requests from hostname ($host) are not allowed");
    }
431798
private function checkPermissions()
    {
        foreach ($this->writableDirectories as $path) {
            if (!$this->filesystem->isWritable(base_path($path))) {
                $this->console->error($path . ' is not writable');
                $this->errors = true;
            }
        }
    }
638285
private function _validate()
	{
		$this->checkOverwritePermission();
		$this->checkHasValidUploadDirectory();
		$this->checkFileSize();
		$this->checkFileTypeIsAllowed();
		$this->checkFileTypeIsNotBlocked();

		return true;
	}
726725
public function write()
    {
        // If the local filesystem has the uploaded file
        if (file_exists($this->file->getRealPath()))
        {
            // Read the local uploaded file
            $file = file_get_contents($this->file->getRealPath());

            // Write it to the S3 location
            return $this->remote->write($this->attributes['upload_to'] . '/' . $this->attributes['filename'], $file, ['visibility' => 'public']);
        }

        throw new Exception('The uploaded file was not found on the filesystem');
    }