Set owner for an existing file.

@throws IOException
2116
public void setOwner(String src, String username, String group
  ) throws IOException {
    INode[] inodes = null;
    writeLock();
    try {
      if (isInSafeMode()) {
        throw new SafeModeException("Cannot set permission for " + src, safeMode);
      }
      inodes = dir.getExistingPathINodes(src);
      if (isPermissionCheckingEnabled(inodes)) {
        FSPermissionChecker pc = checkOwner(src, inodes);
        if (!pc.isSuper) {
          if (username != null && !pc.user.equals(username)) {
            if (this.permissionAuditOnly) {
              // do not throw the exception, we would like to only log.
              LOG.warn("PermissionAudit failed on " + src + 
                  ": non-super user cannot change owner.");
            } else {
              throw new AccessControlException("Non-super user cannot change owner.");
            }
          }
          if (group != null && !pc.containsGroup(group)) {
            if (this.permissionAuditOnly) {
              // do not throw the exception, we would like to only log.
              LOG.warn("PermissionAudit failed on " + src + 
                  ": user does not belong to " + group + " .");
            } else {
              throw new AccessControlException("User does not belong to " + group
                  + " .");
            }
          }
        }
      }
      dir.setOwner(src, username, group);
    } finally {
      writeUnlock();
    }
    getEditLog().logSync(false);
    if (auditLog.isInfoEnabled()) {
      logAuditEvent(getCurrentUGI(),
        Server.getRemoteIp(),
        "setOwner", src, null, getLastINode(inodes));
    }
  }
336836
private void visit_OP_SET_OWNER() throws IOException {
    visitTxId();
    v.visitStringUTF8(EditsElement.PATH);
    v.visitStringUTF8(EditsElement.USERNAME);
    v.visitStringUTF8(EditsElement.GROUPNAME);
  }
159192
public function addOwners()
    {
        foreach ($this->attributes as $attr) {
            if ($mediafile = $this->loadModel($this->owner->$attr)) {
                $mediafile->addOwner($this->owner->primaryKey, $this->name, $attr);
            }
        }
    }
24179
@Override
    public void setFile(File file) {
        configFile = file;
        if (tc.isDebugEnabled())
            Tr.debug(tc, "Jaspi configuration of persistent providers will be stored in file: " + file);
    }
333435
public void setOwner(HttpServiceContext hsc) {
        // if we have an SC owner, set it's flag to false
        if (null != getServiceContext()) {
            getServiceContext().setResponseOwner(false);
        }
        // if the owner is a new HSC, then init the flags
        if (null != hsc) {
            super.init(hsc);
            getServiceContext().setResponseOwner(true);
            setIncoming(!getServiceContext().isInboundConnection());
            if (!isIncoming()) {
                // outgoing responses need header validation checks.. if config
                // hasn't disabled them
                setHeaderValidation(getServiceContext().getHttpConfig().isHeaderValidationEnabled());
            }
        }
    }
561764
public void setOwner(ListenerOwner owner)
    {
        super.setOwner(owner);
        if (owner != null)
        {
            if (mainFieldName == null)
                m_fldMain = this.getOwner().getReferenceField(m_FileToRead);
            if (fileKeyFieldName != null)
                m_FileToRead.setKeyArea(m_FileToRead.getField(fileKeyFieldName));
            else
                m_FileToRead.setKeyArea(m_FileToRead.getField(m_iFileKeyField));
        }
    }
1045331
public void setOwner(ListenerOwner owner)
    {
        super.setOwner(owner);
        if (owner != null) if (m_fldMain != null) if (m_fldMain.getRecord() != owner)
            m_fldMain.addListener(new FieldRemoveBOnCloseHandler(this));
    }
337724
public void setOwner(ListenerOwner owner)
    {
        super.setOwner(owner);
        if (owner != null)
        {
            Record recUserInfo = this.getOwner();
            RecordOwner recordOwner = recUserInfo.getRecordOwner();
            Record recUserScreenRecord = (Record)recordOwner.getScreenRecord();
            // This will flag the password as changed:
            recUserScreenRecord.getField(UserScreenRecord.NEW_PASSWORD_1).addListener(new ChangeOnChangeHandler(recUserInfo.getField(UserInfo.PASSWORD), true));
            recUserScreenRecord.getField(UserScreenRecord.NEW_PASSWORD_2).addListener(new ChangeOnChangeHandler(recUserInfo.getField(UserInfo.PASSWORD), true));
        }
    }
111368
public void setOwner(ListenerOwner owner)
    {
        super.setOwner(owner);
        if (owner != null)
        {
            if (m_fldValue1 != null)
                if (m_fldValue1.getRecord() != this.getOwner().getRecord())
                    m_fldValue1.addListener(new FieldRemoveBOnCloseHandler(this));      // Not same file, if target file closes, remove this listener!
            if (m_fldValue2 != null)
                if (m_fldValue2.getRecord() != this.getOwner().getRecord())
                if (m_fldValue2.getRecord() != m_fldValue1.getRecord())
                    m_fldValue2.addListener(new FieldRemoveBOnCloseHandler(this));      // Not same file, if target file closes, remove this listener!
        }
    }
706075
def _set_shortcut_ownership(path, user):
    '''
    
    '''
    try:
        __salt__['file.lchown'](path, user)
    except OSError:
        pass
    return _check_shortcut_ownership(path, user)
306442
public void setOwner(ListenerOwner owner)
    {
        if (owner == null)
        {
            this.saveValue(m_recordOwnerCache);
            m_recordOwnerCache = null;
        }
        super.setOwner(owner);
        if (owner != null)
            this.retrieveValue();
    }
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);
    }
  }
296861
public void setOwner(ListenerOwner owner)
    {
        super.setOwner(owner);
        if (owner == null)
            return;
        try   {     // Open this table and move to the control record
            if (!this.getOwner().isOpen())
                this.getOwner().open();     // Open the control file
            if (this.getOwner().getEditMode() == Constants.EDIT_NONE)
                this.doNewRecord(true);     // Read the control file
        } catch (DBException e)   {
            return;
        }
    }
871525
public void setOwner(ListenerOwner owner)
    {
        super.setOwner(owner);
        if (this.getOwner() != null)
        {
            if (this.getOwner().getListener(this.getClass()) != this)
                if (((MainFieldHandler)this.getOwner().getListener(this.getClass())).getActualKeyArea() == this.getActualKeyArea())
                    this.getOwner().removeListener(this.getOwner().getListener(this.getClass()), true); // Make sure there is only one of these
        }
    }
278767
def set_owner(self, path, **kwargs):
        
        response = self._put(path, 'SETOWNER', **kwargs)
        assert not response.content
469497
public static final FileAttribute<UserPrincipal> getOwnerAsAttribute(String owner) throws IOException
    {
        if (supports("posix"))
        {
            UserPrincipalLookupService upls = FileSystems.getDefault().getUserPrincipalLookupService();
            UserPrincipal user = upls.lookupPrincipalByName(owner);
            return new FileAttributeImpl<>("posix:owner", user);
        }
        else
        {
            return null;
        }
    }
171243
public void setOwner(ListenerOwner owner)
    {
        super.setOwner(owner);
        if (owner == null)
            return;
        if (m_fldThisFile == null)
            if (thisFileFieldName != null)
                m_fldThisFile = this.getOwner().getField(thisFileFieldName);
        if (m_fldThisFile2 == null)
            if (thisFileFieldName2 != null)
                m_fldThisFile2 = this.getOwner().getField(thisFileFieldName2);
        if (m_fldThisFile3 == null)
            if (thisFileFieldName3 != null)
                m_fldThisFile3 = this.getOwner().getField(thisFileFieldName3);
//?        if (m_fldThisFile != null)
//?            m_fldThisFile.saveEnableListeners(false);     // Don't let behaviors mess with my values.
//?        if (m_fldThisFile2 != null)
//?            m_fldThisFile2.saveEnableListeners(false);    // Note: This is because of a conflict with.
//?        if (m_fldThisFile3 != null)
//?            m_fldThisFile3.saveEnableListeners(false);    // InitOnceFieldHandler, the value is only set once.
//x        this.setMainKey(true, null);    // Initialize the keys
    }