我正在尝试向 Perforce 中的文件夹授予权限。但是,在 Perforce 中通过 Java 创建/更新的权限表是空的。
以下是我执行的步骤 -
//Get the server object.
IOptionsServer server = ServerFactory.getOptionsServer("p4java://<ip>:1666", null);
server.connect();
server.setUserName("<username>"); // this is a super user
server.login("<password>");
//Create a user group and add users.
IUserGroup ug = new UserGroup();
String groupName = "<usergroup_somename>;
ug.setName(groupName);
List<String> userList = new ArrayList<>();
userList.add("<username1>");
userList.add("<username2>");
userList.add("<username3>");
ug.setUsers(userList);
server.createUserGroup(ug);
//Get the permission table.
GetProtectionEntriesOptions gpo = new GetProtectionEntriesOptions();
gpo.setAllUsers(true);
List<IProtectionEntry> peList = server.getProtectionEntries(null, gpo);
//Create a new Protection entry
IProtectionEntry pe = new ProtectionEntry();
pe.setGroup(true);
pe.setName(groupName);
depotFilePath = "//depottest/Level1/Level2/..."; // the folders exist in Perforce
pe.setPath(depotFilePath);
pe.setMode("write");
pe.setHost("*");
pe.setPathExcluded(false);
pe.setOrder(peList.size());
pe.setType(EntryType.INCLUDE);
//Add the new created permission into the fetched Permission table list.
peList.add(pe);
//Create/Update the Permission table using either of the following methods separately or in combination creates a blank permission table.
server.createProtectionEntries(peList);
server.updateProtectionEntries(peList);
根据documentation最后的方法应该创建/替换/更新权限表,但是,这不会发生,而是 Perforce 服务器中的权限表被删除/空白。
我可能错过了一些东西。有人可以就如何解决这个问题提出一些建议吗?
附注我尝试仅使用 updateProtectionEntries(peList)
方法或 server.createProtectionEntries(peList)
方法,并且将两者一起使用,但 Perforce 服务器中的许可表仍然为空。
最佳答案
Perforce 有论坛,您可以在其中提问:forums.perforce.com
有时(取决于 P4Java 和服务器版本)不正确的订单值可能会丢失数据。还有一个路径中的空格问题。
这对我有用:
peList.add(pe);
// fix order values and spaces-in-path quoting
int i = 0;
for (IProtectionEntry pe : peList) {
pe.setOrder(i++);
if (pe.getPath().indexOf(" ") >= 0) {
// this bug should be fixed in 2014.X (no promises)
if (pe.isPathExcluded()) {
pe.setPath("\"-" + pe.getPath() + "\"");
pe.setPathExcluded(false);
} else {
pe.setPath("\"" + pe.getPath() + "\"");
}
}
}
try {
String createProtectionEntries = server.createProtectionEntries(peList);
关于java - 通过java追加perforce权限表会导致权限表为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24305788/