From 9b5f54e36733854fc8d6897808ce53349cf7b785 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Thu, 6 May 2021 11:38:23 -0700 Subject: [PATCH] java: filer client add modified time to touch() function --- .../java/seaweedfs/client/FilerClient.java | 40 +++++++++++-------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/other/java/client/src/main/java/seaweedfs/client/FilerClient.java b/other/java/client/src/main/java/seaweedfs/client/FilerClient.java index 257a9873d..91e7cba57 100644 --- a/other/java/client/src/main/java/seaweedfs/client/FilerClient.java +++ b/other/java/client/src/main/java/seaweedfs/client/FilerClient.java @@ -142,10 +142,12 @@ public class FilerClient extends FilerGrpcClient { public boolean touch(String path, int mode) { String currentUser = System.getProperty("user.name"); - return touch(path, mode, 0, 0, currentUser, new String[]{}); + + long now = System.currentTimeMillis() / 1000L; + return touch(path, now, mode, 0, 0, currentUser, new String[]{}); } - public boolean touch(String path, int mode, int uid, int gid, String userName, String[] groupNames) { + public boolean touch(String path, long modifiedTimeSecond, int mode, int uid, int gid, String userName, String[] groupNames) { File pathFile = new File(path); String parent = pathFile.getParent().replace('\\','/'); @@ -155,17 +157,25 @@ public class FilerClient extends FilerGrpcClient { if (entry == null) { return createEntry( parent, - newFileEntry(name, mode, uid, gid, userName, groupNames).build() + newFileEntry(name, modifiedTimeSecond, mode, uid, gid, userName, groupNames).build() ); } - long now = System.currentTimeMillis() / 1000L; - FilerProto.FuseAttributes.Builder attr = entry.getAttributes().toBuilder() - .setMtime(now) - .setUid(uid) - .setGid(gid) - .setUserName(userName) - .clearGroupName() - .addAllGroupName(Arrays.asList(groupNames)); + FilerProto.FuseAttributes.Builder attr = entry.getAttributes().toBuilder(); + if (modifiedTimeSecond>0) { + attr.setMtime(modifiedTimeSecond); + } + if (uid>0) { + attr.setUid(uid); + } + if (gid>0) { + attr.setGid(gid); + } + if (userName!=null) { + attr.setUserName(userName); + } + if (groupNames!=null) { + attr.clearGroupName().addAllGroupName(Arrays.asList(groupNames)); + } return updateEntry(parent, entry.toBuilder().setAttributes(attr).build()); } @@ -188,17 +198,15 @@ public class FilerClient extends FilerGrpcClient { .addAllGroupName(Arrays.asList(groupNames))); } - public FilerProto.Entry.Builder newFileEntry(String name, int mode, + public FilerProto.Entry.Builder newFileEntry(String name, long modifiedTimeSecond, int mode, int uid, int gid, String userName, String[] groupNames) { - long now = System.currentTimeMillis() / 1000L; - return FilerProto.Entry.newBuilder() .setName(name) .setIsDirectory(false) .setAttributes(FilerProto.FuseAttributes.newBuilder() - .setMtime(now) - .setCrtime(now) + .setMtime(modifiedTimeSecond) + .setCrtime(modifiedTimeSecond) .setUid(uid) .setGid(gid) .setFileMode(mode)