1

我正在尝试向 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);

根据文档,最终的方法应该创建/替换/更新权限表,但是,这不会发生,而是 Perforce 服务器中的权限表被删除/空白。

我可能会遗漏一些东西。有人可以就如何解决这个问题提出一些建议吗?

PS我试过只使用updateProtectionEntries(peList)方法或server.createProtectionEntries(peList)方法,两者一起使用,但Perforce服务器中的权限表仍然是空白的。

4

1 回答 1

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);
于 2014-06-20T22:45:07.030 回答