Creates a staging directory with the permission as in source directory.
@param fs filesystem object
@param destination staging directory location
@param conversionEntity conversion entity used to get source directory permissions
@param workUnit workunit
503400
public static void createStagingDirectory(FileSystem fs, String destination, HiveProcessingEntity conversionEntity,
      WorkUnitState workUnit) {
    /*
     * Create staging data location with the same permissions as source data location
     *
     * Note that hive can also automatically create the non-existing directories but it does not
     * seem to create it with the desired permissions.
     * According to hive docs permissions for newly created directories/files can be controlled using uMask like,
     *
     * SET hive.warehouse.subdir.inherit.perms=false;
     * SET fs.permissions.umask-mode=022;
     * Upon testing, this did not work
     */
    Path destinationPath = new Path(destination);
    try {
      FsPermission permission;
      String group = null;
      if (conversionEntity.getTable().getDataLocation() != null) {
        FileStatus sourceDataFileStatus = fs.getFileStatus(conversionEntity.getTable().getDataLocation());
        permission = sourceDataFileStatus.getPermission();
        group = sourceDataFileStatus.getGroup();
      } else {
        permission = FsPermission.getDefault();
      }

      if (!fs.mkdirs(destinationPath, permission)) {
        throw new RuntimeException(String.format("Failed to create path %s with permissions %s",
            destinationPath, permission));
      } else {
        fs.setPermission(destinationPath, permission);
        // Set the same group as source
        if (group != null && !workUnit.getPropAsBoolean(HIVE_DATASET_DESTINATION_SKIP_SETGROUP, DEFAULT_HIVE_DATASET_DESTINATION_SKIP_SETGROUP)) {
          fs.setOwner(destinationPath, null, group);
        }
        log.info(String.format("Created %s with permissions %s and group %s", destinationPath, permission, group));
      }
    } catch (IOException e) {
      Throwables.propagate(e);
    }
  }
498090
private static List<CopyPath> expandDirectories(FileSystem fs,
      List<Path> paths, Path dstPath)
      throws IOException {
    List<CopyPath> newList = new ArrayList<CopyPath>();
    FileSystem dstFs = dstPath.getFileSystem(defaultConf);

    boolean isDstFile = false;
    try {
      FileStatus dstPathStatus = dstFs.getFileStatus(dstPath);
      if (!dstPathStatus.isDir()) {
        isDstFile = true;
      }
    } catch (FileNotFoundException e) {
      isDstFile = true;
    }

    for (Path path : paths) {
      FileStatus pathStatus = fs.getFileStatus(path);
      if (!pathStatus.isDir()) {
        // This is the case where the destination is a file, in this case, we
        // allow only a single source file. This check has been done below in
        // FastCopy#parseFiles(List, String[])
        if (isDstFile) {
          newList.add(new CopyPath(path, dstPath));
        } else {
          newList.add(new CopyPath(path, new Path(dstPath, path.getName())));
        }
      } else {
        // If we are copying /a/b/c into /x/y/z and 'z' does not exist, we
        // create the structure /x/y/z/f*, where f* represents all files and
        // directories in c/
        Path rootPath = dstPath;
        // This ensures if we copy a directory like /a/b/c to a directory
        // /x/y/z/, we will create the directory structure /x/y/z/c, if 'z'
        // exists.
        if (dstFs.exists(dstPath)) {
          rootPath = new Path(dstPath, pathStatus.getPath().getName());
        }
        getDirectoryListing(pathStatus, fs, newList, rootPath);
      }
    }
    return newList;
  }
1003526
private static void serializeFsPermissions(State state, String key, FsPermission fsPermissions) {
    state.setProp(key, String.format("%04o", fsPermissions.toShort()));
  }
598964
public static FsPermission deserializeWriterFilePermissions(State state, int numBranches, int branchId) {
    return new FsPermission(state.getPropAsShortWithRadix(
        ForkOperatorUtils.getPropertyNameForBranch(ConfigurationKeys.WRITER_FILE_PERMISSIONS, numBranches, branchId),
        FsPermission.getDefault().toShort(), ConfigurationKeys.PERMISSION_PARSING_RADIX));
  }
925163
@Override
    public void moveObject(final FedoraSession session, final String source, final String destination) {
        final Session jcrSession = getJcrSession(session);
        try {
            final FedoraResource srcResource = find(session, source);
            final Node sourceNode = getJcrNode(srcResource);
            final String name = sourceNode.getName();
            final Node parent = sourceNode.getDepth() > 0 ? sourceNode.getParent() : null;

            jcrSession.getWorkspace().move(source, destination);

            if (parent != null) {
                createTombstone(parent, name);
            }

            touchLdpMembershipResource(getJcrNode(find(session, source)));
            touchLdpMembershipResource(getJcrNode(find(session, destination)));

        } catch (final RepositoryException e) {
            throw new RepositoryRuntimeException(e);
        }
    }
481536
public final void checkPermission( Destination destination , String action ) throws JMSException
    {
    	if (securityContext == null)
            return; // Security is disabled
    	
    	DestinationRef destinationRef = DestinationTools.asRef(destination);
    	securityContext.checkPermission(destinationRef.getResourceName(), action);        
    }
819817
public void createDestination(com.ibm.ws.sib.admin.DestinationDefinition dd)throws JMSException
  {
		if (tcInt.isEntryEnabled()) SibTr.entry(tcInt, "createDestination(DestinationDefinition)");
  	try
  	{
  		Reliability defRel = dd.getDefaultReliability();
  		if(defRel == null)
  		{
				dd.setDefaultReliability(Reliability.ASSURED_PERSISTENT);
  		}
  		
  		Reliability maxRel = dd.getMaxReliability();
  		if(maxRel == null)
  		{
				dd.setMaxReliability(Reliability.ASSURED_PERSISTENT);
  		}
  		
			LocalizationDefinition dloc = null;//JsAdminFactory.getInstance().createLocalizationDefinition(dd.getName());
			//lohith liberty change
			admin.createDestinationLocalization(dd, dloc);  // createDestinationLocalization(dd, dloc, null, null, null, null);
  	}
		catch(Exception e)
		{
      // No FFDC code needed
			if (tcInt.isEntryEnabled()) SibTr.debug(tcInt, "Exception creating Destination Localisation", e);
			if (tcInt.isEntryEnabled()) SibTr.exit(tcInt, "createDestination(DestinationDefinition)");
			throw new RuntimeException("Unable to create Destination Localization", e);
		}
		if (tcInt.isEntryEnabled()) SibTr.exit(tcInt, "createDestination(DestinationDefinition)");
  }
1116945
function createDestination(destination) {
    const folders = destination.split(separator);
    const pathParts = [];
    const l = folders.length;

    // for absolute paths
    if (folders[0] === '') {
        pathParts.push(separator);
        folders.shift();
    }

    for (let i = 0; i < l; i++) {
        pathParts.push(folders[i]);

        if (folders[i] !== '' && !doesPathExist(pathParts.join(separator))) {
            try {
                fs.mkdirSync(pathParts.join(separator));
            } catch (error) {
                throw new PluginError('gulp-copy', `Could not create destination <${destination}>: ${error.message}`);
            }
        }
    }
}
358239
public static OwnerAndPermission resolveReplicatedOwnerAndPermission(FileSystem fs, Path path,
      CopyConfiguration copyConfiguration) throws IOException {

    PreserveAttributes preserve = copyConfiguration.getPreserve();
    Optional<FileStatus> originFileStatus = copyConfiguration.getCopyContext().getFileStatus(fs, path);

    if (!originFileStatus.isPresent()) {
      throw new IOException(String.format("Origin path %s does not exist.", path));
    }

    String group = null;
    if (copyConfiguration.getTargetGroup().isPresent()) {
      group = copyConfiguration.getTargetGroup().get();
    } else if (preserve.preserve(Option.GROUP)) {
      group = originFileStatus.get().getGroup();
    }

    return new OwnerAndPermission(preserve.preserve(Option.OWNER) ? originFileStatus.get().getOwner() : null, group,
        preserve.preserve(Option.PERMISSION) ? originFileStatus.get().getPermission() : null);
  }
1252278
public String copyScriptContent(final ExecutionContext executionContext, final String s,
                                    final INodeEntry node, final String destination) throws
                                                           FileCopierException {
        return copyFile(executionContext, null, null, s, node, destination);
    }
628251
protected void moveResource(CmsDbContext dbc, CmsResource source, String destination) throws CmsException {

        List<CmsResource> resources = null;

        if (source.isFolder()) {
            if (!CmsResource.isFolder(destination)) {
                // ensure folder name end's with a /
                destination = destination.concat("/");
            }
            // collect all resources in the folder without checking permissions
            resources = m_driverManager.readChildResources(dbc, source, CmsResourceFilter.ALL, true, true, false);
        }

        // target permissions will be checked later
        m_driverManager.moveResource(dbc, source, destination, false);

        // make sure lock is set
        CmsResource destinationResource = m_driverManager.readResource(dbc, destination, CmsResourceFilter.ALL);
        try {
            // the destination must always get a new lock
            m_driverManager.lockResource(dbc, destinationResource, CmsLockType.EXCLUSIVE);
        } catch (Exception e) {
            // could happen with with shared locks on single files
            if (LOG.isWarnEnabled()) {
                LOG.warn(e);
            }
        }

        if (resources != null) {
            // now walk through all sub-resources in the folder
            for (int i = 0; i < resources.size(); i++) {
                CmsResource childResource = resources.get(i);
                String childDestination = destination.concat(childResource.getName());
                // recurse with child resource
                moveResource(dbc, childResource, childDestination);
            }
        }
        CmsProject currentProject = dbc.getRequestContext().getCurrentProject();
        if (!currentProject.isOnlineProject()) {
            List<CmsResource> movedResources = m_driverManager.readChildResources(
                dbc,
                destinationResource,
                CmsResourceFilter.ALL,
                true,
                true,
                false);
            movedResources.add(destinationResource);
            for (CmsResource res : movedResources) {
                m_driverManager.repairCategories(dbc, dbc.getRequestContext().getCurrentProject().getUuid(), res);
            }
        }
    }
548265
@Override
    public JsDestinationAddress createSystemDestination(String prefix)
                    throws SIResourceException, SIMPDestinationAlreadyExistsException, SIIncorrectCallException
    {
        //prefixes should be unique, 24 chars or less and
        //can contain the characters a-z, A-Z, 0-9, ., /, and %.
        boolean valid = isDestinationPrefixValid(prefix);
        if (!valid)
        {
            throw new SIInvalidDestinationPrefixException(
                            nls.getFormattedMessage(
                                                    "INVALID_DESTINATION_PREFIX_ERROR_CWSIP0023",
                                                    new Object[] { prefix },
                                                    null));
        }

        return _destinationManager.createSystemDestination(prefix);
    }
1249288
private function ensuredCopyDir($source, $destination)
    {
        try
        {
            $filesList = $this->getContents($source);

            foreach ($filesList as $file)
            {
                $path = $file['path'];
                $dest = explode(DIRECTORY_SEPARATOR, $path, 2);
                $dest = $destination . DIRECTORY_SEPARATOR . $dest[1];

                if ($file['type'] === Filesystem::TYPE_DIRECTORY)
                {
                    $this->copyDir($path, $dest);
                }
                else if ($file['type'] === Filesystem::TYPE_FILE)
                {
                    $this->copyFile($path, $dest);
                }
            }

            return;
        }
        catch (Error $ex)
        {}
        catch (Exception $ex)
        {}

        throw new WriteException("Directory $source could not be copied to $destination.");
    }
19766
protected void createTransmissionDestination(SIBUuid8 remoteMEUuid) throws SIResourceException, SIMPDestinationAlreadyExistsException
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(tc, "createTransmissionDestination", remoteMEUuid);
        String destinationName = remoteMEUuid.toString();
        DestinationDefinition destinationDefinition;

        destinationDefinition = messageProcessor.createDestinationDefinition(DestinationType.QUEUE, destinationName);
        destinationDefinition.setMaxReliability(Reliability.ASSURED_PERSISTENT);
        destinationDefinition.setDefaultReliability(Reliability.ASSURED_PERSISTENT);
        Set<String> destinationLocalizingSet = new HashSet<String>();
        destinationLocalizingSet.add(messageProcessor.getMessagingEngineUuid().toString());

        // Create the transmission destination
        createDestinationLocalization(
                                      destinationDefinition,
                                      messageProcessor.createLocalizationDefinition(destinationDefinition.getName()),
                                      destinationLocalizingSet,
                                      false);
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(tc, "createTransmissionDestination");
    }
761230
public function moveFiles(Filesystem $source, Filesystem $destination): void
    {
        foreach ($source->listContents() as $path) {
            if ($path['type'] === 'file') {
                $destination->put($path['path'], $source->read($path['path']));
                $source->delete($path['path']);

                if ($this->timeout_service->isTimeNearlyUp()) {
                    throw new InternalServerErrorException(I18N::translate('The server’s time limit has been reached.'));
                }
            }
        }
    }
421856
@Override
    public void registerTransformers(SubsystemTransformerRegistration subsystemRegistration) {
        ResourceTransformationDescriptionBuilder builder = ResourceTransformationDescriptionBuilder.Factory.createSubsystemInstance();
        builder.addChildResource(DeploymentPermissionsResourceDefinition.DEPLOYMENT_PERMISSIONS_PATH).
                getAttributeBuilder().addRejectCheck(new RejectAttributeChecker.DefaultRejectAttributeChecker() {

            @Override
            protected boolean rejectAttribute(PathAddress address, String attributeName, ModelNode value, TransformationContext context) {
                // reject the maximum set if it is defined and empty as that would result in complete incompatible policies
                // being used in nodes running earlier versions of the subsystem.
                if (value.isDefined() && value.asList().isEmpty()) { return true; }
                return false;
            }

            @Override
            public String getRejectionLogMessage(Map<String, ModelNode> attributes) {
                return SecurityManagerLogger.ROOT_LOGGER.rejectedEmptyMaximumSet();
            }
        }, DeploymentPermissionsResourceDefinition.MAXIMUM_PERMISSIONS);
        TransformationDescription.Tools.register(builder.build(), subsystemRegistration, EAP_7_0_0_MODEL_VERSION);
    }
185042
private static void copyToRemote(Path src, URI dst) throws IOException {
    ResourceId dstId = FileSystems.matchNewResource(dst.toString(), false);
    WritableByteChannel dstCh = FileSystems.create(dstId, MimeTypes.BINARY);
    FileChannel srcCh = FileChannel.open(src, StandardOpenOption.READ);
    long srcSize = srcCh.size();
    long copied = 0;
    do {
      copied += srcCh.transferTo(copied, srcSize - copied, dstCh);
    } while (copied < srcSize);
    dstCh.close();
    srcCh.close();
    Preconditions.checkState(copied == srcSize);
  }