From d5197d6a50b36114d1e96a7846c4550eee947095 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Tue, 4 Dec 2018 00:48:11 -0800 Subject: [PATCH] HCFS support chown --- .../java/seaweed/hdfs/SeaweedFileSystem.java | 18 +++++++++++ .../seaweed/hdfs/SeaweedFileSystemStore.java | 32 +++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/other/java/hdfs/src/main/java/seaweed/hdfs/SeaweedFileSystem.java b/other/java/hdfs/src/main/java/seaweed/hdfs/SeaweedFileSystem.java index 40f152b4f..4181a5119 100644 --- a/other/java/hdfs/src/main/java/seaweed/hdfs/SeaweedFileSystem.java +++ b/other/java/hdfs/src/main/java/seaweed/hdfs/SeaweedFileSystem.java @@ -218,6 +218,24 @@ public class SeaweedFileSystem extends org.apache.hadoop.fs.FileSystem { return seaweedFileSystemStore.getFileStatus(path); } + /** + * Set owner of a path (i.e. a file or a directory). + * The parameters owner and group cannot both be null. + * + * @param path The path + * @param owner If it is null, the original username remains unchanged. + * @param group If it is null, the original groupname remains unchanged. + */ + @Override + public void setOwner(Path path, final String owner, final String group) + throws IOException { + LOG.debug("setOwner path: {}", path); + path = qualify(path); + + seaweedFileSystemStore.setOwner(path, owner, group); + + } + Path qualify(Path path) { return path.makeQualified(uri, workingDirectory); } diff --git a/other/java/hdfs/src/main/java/seaweed/hdfs/SeaweedFileSystemStore.java b/other/java/hdfs/src/main/java/seaweed/hdfs/SeaweedFileSystemStore.java index 41e2e9fca..f34de3749 100644 --- a/other/java/hdfs/src/main/java/seaweed/hdfs/SeaweedFileSystemStore.java +++ b/other/java/hdfs/src/main/java/seaweed/hdfs/SeaweedFileSystemStore.java @@ -273,4 +273,36 @@ public class SeaweedFileSystemStore { bufferSize, readAheadQueueDepth); } + + public void setOwner(Path path, String owner, String group) { + + LOG.debug("setOwner path:{} owner:{} group:{}", path, owner, group); + + FilerProto.Entry entry = lookupEntry(path); + if (entry == null) { + LOG.debug("setOwner path:{} entry:{}", path, entry); + return; + } + + FilerProto.Entry.Builder entryBuilder = entry.toBuilder(); + FilerProto.FuseAttributes.Builder attributesBuilder = entry.getAttributes().toBuilder(); + + if (owner != null) { + attributesBuilder.setUserName(owner); + } + if (group != null) { + attributesBuilder.clearGroupName(); + attributesBuilder.addGroupName(group); + } + + entryBuilder.setAttributes(attributesBuilder); + + LOG.debug("setOwner path:{} entry:{}", path, entryBuilder, owner, group); + + filerGrpcClient.getBlockingStub().updateEntry(FilerProto.UpdateEntryRequest.newBuilder() + .setDirectory(getParentDirectory(path)) + .setEntry(entryBuilder) + .build()); + + } }