Performce P4.NET API GetFileMetaData()返回NullReferenceException
我运行了从P4下载的P4api.net示例C#代码,以遍历我拥有的本地P4Performce P4.NET API GetFileMetaData()返回NullReferenceException,.net,api,perforce,p4api.net,.net,Api,Perforce,P4api.net,我运行了从P4下载的P4api.net示例C#代码,以遍历我拥有的本地P4/depot存储库。当示例代码尝试读取子目录和文件的//depot/subdirA时,调用API函数GetFileMetaData()会遇到空指针异常。当//depot/subdirA只有子目录而没有文件时,就会发生这种情况。如果//depot/subdirA有一个或多个文件,则GetFileMetaData()工作正常。我一定是遗漏了什么,因为我假设GetFileMetaData()应该适用于存在或不存在文件的目录 以下
/depot
存储库。当示例代码尝试读取子目录和文件的//depot/subdirA
时,调用API函数GetFileMetaData()
会遇到空指针异常。当//depot/subdirA
只有子目录而没有文件时,就会发生这种情况。如果//depot/subdirA
有一个或多个文件,则GetFileMetaData()
工作正常。我一定是遗漏了什么,因为我假设GetFileMetaData()
应该适用于存在或不存在文件的目录
以下是P4示例代码-有关异常位置,请参阅代码注释:
// if we have the depot path, get a list of the subdirectories from the depot
if (!String.IsNullOrEmpty(depotPath))
{
IList<string> subdirs = _repository.GetDepotDirs(null, String.Format("{0}/*", depotPath));
if ((subdirs != null) && (subdirs.Count >0))
{
subdirectories = P4DirectoryMap.FromDirsOutput(_repository, Workspace, this, subdirs);
foreach (P4Directory dir in subdirectories.Values)
{
dir.InDepot = true;
}
}
IList<FileMetaData> fileList = _repository.GetFileMetaData(null, FileSpec.DepotSpec(String.Format("{0}/*", depotPath)));
// get a list of the files in the directory - debugger hit Null Exception within this call.
if (fileList != null)
{
files = P4FileMap.FromFstatOutput(fileList);
// if the directory contains files from the depot, we can use
// the local path of one of those files to determine the local
// path for this directory
if ((String.IsNullOrEmpty(localPath)) && (files != null) && (files.Count > 0))
{
public IList<FileMetaData> GetFileMetaData(Options options, params FileSpec[] filespecs )
{
P4.P4Command fstatCmd = new P4.P4Command(_connection._p4server, "fstat", true, FileSpec.ToStrings(filespecs));
P4.P4CommandResult r = fstatCmd.Run(options);
if (r.Success != true)
{
P4Exception.Throw(r.ErrorList);
return null;
}
List<FileMetaData> value = new List<FileMetaData>();
foreach (P4.TaggedObject obj in r.TaggedOutput)
// Null Exception was caused by r.TaggedOutput=null when the sub dir has no file.
{
FileMetaData fmd = new FileMetaData();
fmd.FromFstatCmdTaggedData(obj);
value.Add(fmd);
}
return value;
}
我该如何解决这个问题,因为人们可以期望仓库目录包含目录或文件,或者两者都包含,但
GetFileMetaData()
似乎期望目录中始终包含文件?是否需要为传入的“options”参数指定一个选项来防止此异常?或者在调用GetFileMetaData()之前,是否有另一个API调用来检查目录中是否存在代码可以调用的文件?提前感谢您的帮助。此错误已报告,并已在P4API.NET的GA版本中修复。我不确定什么时候发布,但你可以打电话给Performance支持部门询问
同时,这里有一个可能的解决方法,可以查看目录是否为空
String[] cmdargs = new String[1];
cmdargs[0] = depotPath + "/*";
P4Command cmd = new P4Command(rep, "files", true, cmdargs);
P4CommandResult results = cmd.Run(null);
if (results != null && results.TaggedOutput != null)
{
foreach (TaggedObject obj in results.TaggedOutput)
{
// do something with file list if you want
}
}
else
{
Console.WriteLine("No files in this directory!");
}
基本上,它使用与
GetFileMetaData
类似的逻辑,但使用较低级别的命令直接从服务器获取带标签的输出。然后,在调用其他方法之前,可以检查结果集中是否存在目录中的任何文件。您使用的是哪种P4.NET api?提供API和示例代码的链接。我从这里下载了p4api.net.zip:ftp.perforce.com/perforce/r11.1/bin.ntx86。我不知道在哪里可以找到下面提到的p4 randall的固定版本谢谢randall的帮助。我已经联系了P4并要求他们修复。技术支持部还没有回来。我提供了有问题的API。希望P4能有所反应。非常感谢!