Set read-write permissions for the current user on the target path.  Fail silently
    if the path doesn't exist.

    :param str fn: The target filename or path
    :return: None
552833
def set_write_bit(fn):
    # type: (str) -> None
    

    fn = fs_encode(fn)
    if not os.path.exists(fn):
        return
    file_stat = os.stat(fn).st_mode
    os.chmod(fn, file_stat | stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)
    if os.name == "nt":
        from ._winconsole import get_current_user

        user_sid = get_current_user()
        icacls_exe = _find_icacls_exe() or "icacls"
        from .misc import run
        if user_sid:
            _, err = run([icacls_exe, "/grant", "{0}:WD".format(user_sid), "''{0}''".format(fn), "/T", "/C", "/Q"])
            if not err:
                return

    if not os.path.isdir(fn):
        for path in [fn, os.path.dirname(fn)]:
            try:
                os.chflags(path, 0)
            except AttributeError:
                pass
        return None
    for root, dirs, files in os.walk(fn, topdown=False):
        for dir_ in [os.path.join(root, d) for d in dirs]:
            set_write_bit(dir_)
        for file_ in [os.path.join(root, f) for f in files]:
            set_write_bit(file_)
838861
def set_write_bit(fn):
    # type: (str) -> None
    

    fn = fs_encode(fn)
    if not os.path.exists(fn):
        return
    file_stat = os.stat(fn).st_mode
    os.chmod(fn, file_stat | stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)
    if not os.path.isdir(fn):
        for path in [fn, os.path.dirname(fn)]:
            try:
                os.chflags(path, 0)
            except AttributeError:
                pass
        return None
    for root, dirs, files in os.walk(fn, topdown=False):
        for dir_ in [os.path.join(root, d) for d in dirs]:
            set_write_bit(dir_)
        for file_ in [os.path.join(root, f) for f in files]:
            set_write_bit(file_)
221604
def put(self, filepath):
        
        action = self.get_body_argument('action')

        if action['action'] == 'update_group':
            newgrp = action['group']
            try:
                self.fs.update_group(filepath,newgrp)
                self.write({'msg':'Updated group for {}'.format(filepath)})
            except OSError:
                raise tornado.web.HTTPError(404)
        elif action['action'] == 'update_permissions':
            newperms = action['permissions']
            try:
                self.fs.update_permissions(filepath,newperms)
                self.write({'msg':'Updated permissions for {}'.format(filepath)})
            except OSError:
                raise tornado.web.HTTPError(404)
        else:
            raise tornado.web.HTTPError(400)
329324
def _prepare_write_fs(read_fs, cache, read_path, readwrite_mode=True):
    '''
    
    '''

    with _get_write_fs() as write_fs:

        # If opening in read/write or append mode, make sure file data is
        # accessible
        if readwrite_mode:

            if not write_fs.isfile(read_path):
                _touch(write_fs, read_path)

                if read_fs.isfile(read_path):
                    fs.utils.copyfile(
                        read_fs, read_path, write_fs, read_path)

        else:
            _touch(write_fs, read_path)

        yield write_fs
1124675
def check_read_permission(self, user_id, do_raise=True):
        
        return self.network.check_read_permission(user_id, do_raise=do_raise)
46346
def Unlock(fd, path):
  
  try:
    fcntl.flock(fd, fcntl.LOCK_UN | fcntl.LOCK_NB)
  except IOError as e:
    if e.errno == errno.EWOULDBLOCK:
      raise IOError('Exception unlocking %s. Locked by another process.' % path)
    else:
      raise IOError('Exception unlocking %s. %s.' % (path, str(e)))
249647
def file_can_be_read(path):
    
    if path is None:
        return False
    try:
        with io.open(path, "rb") as test_file:
            pass
        return True
    except (IOError, OSError):
        pass
    return False
167254
def write_pid_file(fn):
    
    if not fn:
        return None
    if fn == '' or fn == "''":
        # work around argument passings in init-scripts
        return None
    f = open(fn, "w")
    f.write("%s\n" % (os.getpid()))
    f.close()
968361
def set(self, permissions):
        
        parent_url = self.client.get_url(self.parent_object._manager._URL_KEY, 'GET', 'single', {'id': self.parent_object.id})
        target_url = parent_url + self.client.get_url_path(self._URL_KEY, 'PUT', 'multi')
        r = self.client.request('PUT', target_url, json=permissions)
        if r.status_code != 201:
            raise exceptions.ServerError("Expected 201 response, got %s: %s" % (r.status_code, target_url))
        return self.list()
970734
function fsReaddir(path, cb) {
    if (path === '/') return cb(new Error('Reading filesystem at / is disallowed to prevent mistakes.'));
    fs.readdir(path, function(err, dir) { if (err) return cb(err);
      var ab = asyncbuilder(cb);
      u.each(dir, function(name) {
        var push = ab.asyncAppend();
        fs.stat(u.join(path, name), function(err, stats) {
          var entry = !err && { name:name, type:(stats.isDirectory() ? 'dir' : stats.isFile() ? 'file' : 'other') };
          push(err, entry);
        });
      });
      ab.complete();
    });
  }
388930
def check_input_file_or_directory(self, path):
        
        if (not gf.file_can_be_read(path)) and (not os.path.isdir(path)):
            self.print_error(u"Unable to read file or directory '%s'" % (path))
            self.print_error(u"Make sure the path is written/escaped correctly and that you have read permission on it")
            return False
        return True
1290290
function(callback) {
            // Optional permission modification
            if (disablePerms) {
              callback();
              return;
            }
            
            grunt.verbose.writeln('changing file perms...');

            // 511 = 0777 octal
            ftpout.raw.site('chmod', (file.mode & 511).toString(8), file.dest, function(err) {
              // Windows and some hosts don't implement the CHMOD site extension
              if (err && err.code !== 502 && err.code !== 504) {
                done(err);
                return;
              }

              grunt.verbose.writeln('done changing perms');
              callback();
            });
          }
61599
def set_permissions_mode_from_octal(file_path, code):
    
    # Unpack permissions tuple
    user, group, other = tuple(str(code[-3:])) if len(str(code)) > 3 else tuple(str(code))
    user, group, other = int(user), int(group), int(other)
    mode = get_permissions_mode(user,
                                'user') & get_permissions_mode(group, 'group') & get_permissions_mode(other, 'other')
    os.chmod(file_path, mode)
1091992
public void setPermission(String src, FsPermission permission
                            ) throws IOException {
    checkOpen();
    clearFileStatusCache();
    
    try {
      namenode.setPermission(src, permission);
    } catch(RemoteException re) {
      throw re.unwrapRemoteException(AccessControlException.class,
                                     FileNotFoundException.class);
    }
  }
579647
def can_aquire_user_lock(repository_path, session_token):
    
    # NOTE ALWAYS use within lock access callback

    user_file_path = cpjoin(repository_path, 'user_file')
    if not os.path.isfile(user_file_path): return True
    with open(user_file_path, 'r') as fd2:
        content = fd2.read()
        if len(content) == 0: return True
        try: res = json.loads(content)
        except ValueError: return True
        if res['expires'] < int(time.time()): return True
        elif res['session_token'] == session_token: return True
    return False
14102
function isWriteable(file) {
  let writePermission = true;
  try {
    const __fd = fs.openSync(file, 'a');
    fs.closeSync(__fd);
  } catch (e) {
    /* istanbul ignore next */
    writePermission = false;
  }

  return writePermission;
}
408073
def write(self, fn=None):
        """"""
        fn = fn or self.fn
        if not os.path.exists(os.path.dirname(fn)):
            os.makedirs(os.path.dirname(fn))
        f = open(self.fn, 'rb')
        b = f.read()
        f.close()
        f = open(fn, 'wb')
        f.write(b)
        f.close()