我正在尝试向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,最终的方法应该创建/替换/更新Permission表,但是,这不会发生,而是Perforce服务器中的权限表被删除/空白。
我可能会遗漏一些东西。有人可以就如何解决这个问题提出一些建议吗?
P.S。我尝试过只使用updateProtectionEntries(peList)
方法或server.createProtectionEntries(peList)
方法,并且Perforce服务器中的pemission表仍为空白。
答案 0 :(得分:2)
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);