当前位置: 首页>>代码示例>>Java>>正文


Java PosixFileAttributeView.setOwner方法代码示例

本文整理汇总了Java中java.nio.file.attribute.PosixFileAttributeView.setOwner方法的典型用法代码示例。如果您正苦于以下问题:Java PosixFileAttributeView.setOwner方法的具体用法?Java PosixFileAttributeView.setOwner怎么用?Java PosixFileAttributeView.setOwner使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.nio.file.attribute.PosixFileAttributeView的用法示例。


在下文中一共展示了PosixFileAttributeView.setOwner方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: chown

import java.nio.file.attribute.PosixFileAttributeView; //导入方法依赖的package包/类
@Override
 public void chown(String path, String username, String groupname) throws IOException {
java.nio.file.Path p = FileSystems.getDefault().getPath(path);
PosixFileAttributeView view = Files.getFileAttributeView(p, PosixFileAttributeView.class);
UserPrincipalLookupService service = p.getFileSystem().getUserPrincipalLookupService();
if(!StringUtils.isBlank(username)) {
	view.setOwner(service.lookupPrincipalByName(username));
}
if(!StringUtils.isBlank(groupname)) {
	view.setGroup(service.lookupPrincipalByGroupName(groupname));
}
 }
 
开发者ID:intel-hpdd,项目名称:lustre-connector-for-hadoop,代码行数:13,代码来源:LustreFsJavaImpl.java

示例2: write

import java.nio.file.attribute.PosixFileAttributeView; //导入方法依赖的package包/类
@Override
public boolean write(String path, InputStream is, boolean overwrite) {

	/* If we're a RAF file, remove the "internal" owner. */
	Path p = rootPath.resolve(path);
	if(Files.exists(p)) {
		try {
			PosixFileAttributeView a = Files.getFileAttributeView(p, PosixFileAttributeView.class);
			if(a.getOwner() == rafs.getOwnerPrincipal()) {
				a.setOwner(null);
			}
		} catch(IOException e) {
			if(logger.isErrorEnabled()) {
				logger.error(String.format("Error removing owner attribute on %s. Attempting deletion...", path), e);
			}
			try {
				/* If that failed, try to delete and recreate. */
				Files.delete(p);
				Files.createFile(p);
			} catch(IOException ex) {
				/* If that failed, just die. */
				if(logger.isErrorEnabled()) {
					logger.error("  Deletion failed, aborting write...", e);
				}
				return false;
			}
		}
	}

	return super.write(path, is, overwrite);
}
 
开发者ID:vs49688,项目名称:RAFTools,代码行数:32,代码来源:RAFSResourceRoot.java

示例3: chown

import java.nio.file.attribute.PosixFileAttributeView; //导入方法依赖的package包/类
/**
 * @param localFile the local file to use chown on
 * @param owner the file owner to set
 * @param group the file group to set
 * @throws IOException if chown couldn't be edited
 */
public static void chown(File localFile, String owner, String group) throws IOException {
	PosixFileAttributeView view = FileHelper.getFileAttributes(localFile);
	UserPrincipalLookupService lookupService = FileSystems.getDefault().getUserPrincipalLookupService();
	UserPrincipal fileOwner = lookupService.lookupPrincipalByName(owner);
	GroupPrincipal fileGroup = lookupService.lookupPrincipalByGroupName(group);
	view.setOwner(fileOwner);
	view.setGroup(fileGroup);
}
 
开发者ID:cinovo,项目名称:cloudconductor-agent-redhat,代码行数:15,代码来源:FileHelper.java

示例4: testView

import java.nio.file.attribute.PosixFileAttributeView; //导入方法依赖的package包/类
@Test
public void testView() throws IOException {
  file.setAttribute("owner", "owner", createUserPrincipal("user"));

  PosixFileAttributeView view =
      provider.view(
          fileLookup(),
          ImmutableMap.of(
              "basic", new BasicAttributeProvider().view(fileLookup(), NO_INHERITED_VIEWS),
              "owner", new OwnerAttributeProvider().view(fileLookup(), NO_INHERITED_VIEWS)));
  assertNotNull(view);

  assertThat(view.name()).isEqualTo("posix");
  assertThat(view.getOwner()).isEqualTo(createUserPrincipal("user"));

  PosixFileAttributes attrs = view.readAttributes();
  assertThat(attrs.fileKey()).isEqualTo(0);
  assertThat(attrs.owner()).isEqualTo(createUserPrincipal("user"));
  assertThat(attrs.group()).isEqualTo(createGroupPrincipal("group"));
  assertThat(attrs.permissions()).isEqualTo(PosixFilePermissions.fromString("rw-r--r--"));

  view.setOwner(createUserPrincipal("root"));
  assertThat(view.getOwner()).isEqualTo(createUserPrincipal("root"));
  assertThat(file.getAttribute("owner", "owner")).isEqualTo(createUserPrincipal("root"));

  view.setGroup(createGroupPrincipal("root"));
  assertThat(view.readAttributes().group()).isEqualTo(createGroupPrincipal("root"));
  assertThat(file.getAttribute("posix", "group")).isEqualTo(createGroupPrincipal("root"));

  view.setPermissions(PosixFilePermissions.fromString("rwx------"));
  assertThat(view.readAttributes().permissions())
      .isEqualTo(PosixFilePermissions.fromString("rwx------"));
  assertThat(file.getAttribute("posix", "permissions"))
      .isEqualTo(PosixFilePermissions.fromString("rwx------"));
}
 
开发者ID:google,项目名称:jimfs,代码行数:36,代码来源:PosixAttributeProviderTest.java

示例5: defineFilePosixAttributeView

import java.nio.file.attribute.PosixFileAttributeView; //导入方法依赖的package包/类
/**
 * Define file posix attribute view on a path/file.
 *
 * @param path Target path
 * @param filePermissions Permissions to apply
 * @param fileOwner File owner
 * @param fileGroup File group
 * @throws IOException If IO error during definition of file attribute view
 */
public static void defineFilePosixAttributeView(final Path path,
        final Set<PosixFilePermission> filePermissions,
        final String fileOwner,
        final String fileGroup) throws IOException {
    final PosixFileAttributeView view = Files.getFileAttributeView(path, PosixFileAttributeView.class);
    if (view != null) {
        final UserPrincipalLookupService lookupService = FileSystems.getDefault()
                .getUserPrincipalLookupService();
        if (fileOwner != null) {
            final UserPrincipal userPrincipal = lookupService.lookupPrincipalByName(fileOwner);
            if (userPrincipal != null) {
                // If not sudoers member, it will throw Operation not permitted
                // Only processes with an effective user ID equal to the user ID
                // of the file or with appropriate privileges may change the ownership of a file.
                // If _POSIX_CHOWN_RESTRICTED is in effect for path
                view.setOwner(userPrincipal);
            }
        }
        if (fileGroup != null) {
            final GroupPrincipal groupPrincipal = lookupService.lookupPrincipalByGroupName(fileGroup);
            if (groupPrincipal != null) {
                // The current user id should be members of this group,
                // if not will raise Operation not permitted
                view.setGroup(groupPrincipal);
            }
        }
        if (filePermissions != null) {
            view.setPermissions(filePermissions);
        }
    }
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:41,代码来源:FileUtils.java

示例6: addFile

import java.nio.file.attribute.PosixFileAttributeView; //导入方法依赖的package包/类
/**
 * Add a RAF Archive to the VFS.
 *
 * @param raf The path to the index (.raf)
 * @param dat The path to the data (.raf.dat)
 * @param versionName The version of this file.
 * @throws IOException If an I/O error occurred.
 */
public void addFile(Path raf, Path dat, String versionName) throws IOException {
	int lOffset, sOffset;
	int magic, version, mgrIndex;

	try(FileInputStream rfis = new FileInputStream(raf.toFile())) {
		MappedByteBuffer buffer;

		/* Map the file into memory */
		try(FileChannel fChannel = rfis.getChannel()) {
			buffer = fChannel.map(FileChannel.MapMode.READ_ONLY, 0, fChannel.size());
			buffer.order(ByteOrder.LITTLE_ENDIAN);
		}

		/* Check the magic number */
		if((magic = buffer.getInt()) != RAFIDX_MAGIC) {
			throw new IOException(String.format("%s: Invalid magic number. Expected 0x%X, got 0x%X\n", versionName, RAFIDX_MAGIC, magic));
		}

		/* Make sure we're version 1 */
		if((version = buffer.getInt()) != 1) {
			throw new IOException(String.format("%s: Unsupported version %d\n", versionName, version));
		}

		/* No idea what this does. Appears to be always 0 */
		mgrIndex = buffer.getInt();

		if(mgrIndex != 0) {
			System.err.printf("%s: WARNING: mgrIndex field non-zero. Please take note of this and email the developer.\n", versionName);
		}

		/* Read the file list and string offsets */
		lOffset = buffer.getInt();
		sOffset = buffer.getInt();

		/* Read the string table */
		buffer.position(sOffset);
		List<String> st = readStringTable(buffer);

		/* A mapping of the offsets in the string table to their FileNode */
		List<Path> indexMap = new ArrayList<>(st.size());

		for(final String s : st) {

			Path path = this.getRoot().resolve(s);

			Path parent = path.getParent();
			try {
				Files.createDirectories(parent);
			} catch(FileAlreadyExistsException e) {
			}

			if(!Files.exists(path)) {
				Files.createFile(path);
				PosixFileAttributeView a = Files.getFileAttributeView(path, PosixFileAttributeView.class);
				a.setOwner(m_RAFOwnerPrincipal);

				m_NotifyDispatch.onAdd(path);
			}

			indexMap.add(path);
		}

		/* Read the file list */
		buffer.position(lOffset);
		readFileList(buffer, indexMap, st, versionName, dat);
	}
}
 
开发者ID:vs49688,项目名称:RAFTools,代码行数:76,代码来源:RAFS.java

示例7: unsetRAF

import java.nio.file.attribute.PosixFileAttributeView; //导入方法依赖的package包/类
void unsetRAF() throws IOException {
	PosixFileAttributeView a = Files.getFileAttributeView(path, PosixFileAttributeView.class);
	if(a.getOwner() == m_RAFS.getOwnerPrincipal()) {
		a.setOwner(null);
	}
}
 
开发者ID:vs49688,项目名称:RAFTools,代码行数:7,代码来源:RAFSResource.java


注:本文中的java.nio.file.attribute.PosixFileAttributeView.setOwner方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。