Check if some common file locations are writable.
194622
protected function writableFolderCheck()
    {
        $fileName = '/configtester_' . date('Y-m-d-h-i-s') . '.txt';

        $fileSystems = [
            ['name' => 'files', 'folder' => '', 'label' => '<code>files/</code> in the webroot'],
            ['name' => 'extensions', 'folder' => '', 'label' => '<code>extensions/</code> in the webroot'],
            ['name' => 'config', 'folder' => ''],
            ['name' => 'cache', 'folder' => ''],
        ];
        if ($this->app['config']->get('general/database/driver') === 'pdo_sqlite') {
            $fileSystems[] = ['name' => 'app', 'folder' => 'database'];
        }
        $fileSystems = Bag::fromRecursive($fileSystems);

        foreach ($fileSystems as $fileSystem) {
            $contents = $this->isWritable($fileSystem, $fileName);
            if ($contents != 'ok') {
                $folderName = $this->getFoldername($fileSystem);
                $notice = json_encode([
                    'severity' => 1,
                    'notice'   => 'Bolt needs to be able to <strong>write files to</strong> the folder <code>' . $folderName . "</code>, but it doesn't seem to be writable.",
                    'info'     => 'Make sure the folder exists, and is writable to the webserver.',
                ]);
                $this->app['logger.flash']->configuration($notice);
            }
        }
    }
1263555
protected function checkFilePermissions()
    {
        foreach ($this->requiredWritableFolders as $folder) {
            $folderPath = FLOW_PATH_ROOT . $folder;
            if (!is_dir($folderPath) && !\Neos\Utility\Files::is_link($folderPath)) {
                try {
                    \Neos\Utility\Files::createDirectoryRecursively($folderPath);
                } catch (\Neos\Flow\Utility\Exception $exception) {
                    return new Error('Unable to create folder "%s". Check your file permissions (did you use flow:core:setfilepermissions?).', 1330363887, [$folderPath]);
                }
            }
            if (!is_writable($folderPath)) {
                return new Error('The folder "%s" is not writable. Check your file permissions (did you use flow:core:setfilepermissions?)', 1330372964, [$folderPath]);
            }
        }

        return null;
    }
432300
def isignored(self, relpath, directory=False):
    """"""
    relpath = self._relpath_no_dot(relpath)
    if directory:
      relpath = self._append_trailing_slash(relpath)
    return self.ignore.match_file(relpath)
1316007
def has_files(the_path):
    """"""
    the_path = Path(the_path)
    try:
        for _ in the_path.walkfiles():
            return True
        return False
    except OSError as ex:
        if ex.errno == errno.ENOENT:
            # ignore
            return False
        else:
            raise
575088
def hasBeenRotated(self):
      """"""
      try:
         # If the inodes don't match, it means the file has been replaced.
         # The inode number cannot be recycled as long as we hold the
         # filehandle open, so this test can be trusted.
         return os.stat(self._path).st_ino != self._inode
      except OSError:
         # If the file doesn't exist, let's call it "rotated".
         return True
966053
public function canWriteConfiguration()
    {
        $fileLocation = SettingsFiles::getOverrideSettingsFile();

        return @is_writable(file_exists($fileLocation) ? $fileLocation : Environment::getConfigPath() . '/');
    }
442151
def ensure_writable(self):
        """"""
        self.ensure_exists()
        if not self.context.is_writable(self.directory):
            if self.context.have_superuser_privileges:
                msg = "The directory %s isn't writable!"
                raise ValueError(msg % self)
            else:
                raise ValueError(compact("""
                    The directory {location} isn't writable, most likely due
                    to permissions. Consider using the --use-sudo option.
                """, location=self))
1147609
def _compare_file(self, local, remote):
        """"""
        assert isinstance(local, FileEntry) and isinstance(remote, FileEntry)

        if not local or not remote:
            write("    Files cannot be compared ({} != {}).".format(local, remote))
            return False
        elif local.size != remote.size:
            write(
                "    Files are different (size {:,d} != {:,d}).".format(
                    local.size, remote.size
                )
            )
            return False

        with local.target.open_readable(
            local.name
        ) as fp_src, remote.target.open_readable(remote.name) as fp_dest:
            res, ofs = byte_compare(fp_src, fp_dest)

        if not res:
            write("    Files are different at offset {:,d}.".format(ofs))
        else:
            write("    Files are equal.")
        return res
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
113532
def write(self):
        """"""
        self._assure_writable("write")
        if not self._dirty:
            return

        if isinstance(self._file_or_files, (list, tuple)):
            raise AssertionError("Cannot write back if there is not exactly a single file to write to, have %i files"
                                 % len(self._file_or_files))
        # end assert multiple files

        if self._has_includes():
            log.debug("Skipping write-back of configuration file as include files were merged in." +
                      "Set merge_includes=False to prevent this.")
            return
        # end

        fp = self._file_or_files

        # we have a physical file on disk, so get a lock
        is_file_lock = isinstance(fp, string_types + (FileType, ))
        if is_file_lock:
            self._lock._obtain_lock()
        if not hasattr(fp, "seek"):
            with open(self._file_or_files, "wb") as fp:
                self._write(fp)
        else:
            fp.seek(0)
            # make sure we do not overwrite into an existing file
            if hasattr(fp, 'truncate'):
                fp.truncate()
            self._write(fp)
930312
def _write_file_safely(local_path, fileinfo, response):
    """"""
    try:
        _write_file(local_path, fileinfo, response)
    except BaseException as e:
        logger.warning("{} interrupted writing {} -- "
                       "cleaning up partial file".format(
                       e.__class__.__name__, local_path))
        os.remove(local_path)
        raise e
895251
public static function existsDirWritable($dir)
    {
        if (!is_dir($dir)) {
            return false;
        }

        $testFile = $dir . "/write_file_" . time() . ".txt";
        if (!@file_put_contents($testFile, "WRITABLE TEST")) {
            return false;
        } else {
            @unlink($testFile);
        }

        return true;
    }
162443
public function isWritable()
        {
                if (file_exists($this->phpids_base.self::FILENAME_RULES) &&
                        is_writable($this->phpids_base.self::FILENAME_RULES) &&
                        file_exists($this->phpids_base.self::FILENAME_CONVERTER) &&
                        is_writable($this->phpids_base.self::FILENAME_CONVERTER)) {
                        return true;
                } else {
            return false;
                }

        }
325815
private boolean hasFileChangedUnexpectedly() {
        synchronized (this) {
            if (mDiskWritesInFlight > 0) {
                // If we know we caused it, it's not unexpected.
                if (DEBUG) System.out.println( "disk write in flight, not unexpected.");
                return false;
            }
        }
        if (!mFile.canRead()) {
            return true;
        }
        synchronized (this) {
            return mStatTimestamp != mFile.lastModified() || mStatSize != mFile.length();
        }
    }
110047
def make_writeable(filename):
    
    if not os.access(filename, os.W_OK):
        st = os.stat(filename)
        new_permissions = stat.S_IMODE(st.st_mode) | stat.S_IWUSR
        os.chmod(filename, new_permissions)
794347
def verify_file_exists(file_name, file_location):
    
    return __os.path.isfile(__os.path.join(file_location, file_name))
982732
private static void checkLocalDirs(String[] localDirs)
    throws DiskErrorException {
    boolean writable = false;

    if (localDirs != null) {
      for (int i = 0; i < localDirs.length; i++) {
        try {
          DiskChecker.checkDir(new File(localDirs[i]));
          writable = true;
        } catch(DiskErrorException e) {
          LOG.warn("Task Tracker local " + e.getMessage());
        }
      }
    }

    if (!writable)
      throw new DiskErrorException(
                                   "all local directories are not writable");
  }