Perforce P4API.NET Repository.GetDepotFiles() returns deleted files

2k Views Asked by At

I used the Perforce Repository.GetDepotFiles() and noticed that the function returns files that match the search pattern but also returns files that have been deleted in the Perforce Depot. How do I filter out the search to exclude deleted files?

My code to do file search in Depot:

IList<FileSpec> filesToFind = new List<FileSpec>();
FileSpec fileToFind = new FileSpec(new DepotPath("//depot/....cpp"), null, null, VersionSpec.Head);
filesToFind.Add(fileToFind);
IList<FileSpec> filesFound = pRep.GetDepotFiles(filesToFind, null);
1

There are 1 best solutions below

0
On

Using the command-line p4.exe you can get a list of non-deleted files like this:

  p4 files -e //depot/....cpp

The command p4 files supports a couple of different flags, like '-a' and '-A'. These are supported by p4api.net.dll:

  Options options = new FilesCmdOptions(FilesCmdFlags.AllRevisions, maxItems: 10);
  IList<FileSpec> filesFound = rep.GetDepotFiles(filesToFind, options);

FilesCmdFlags.AllRevisions corresponds to the '-a' flag (and FilesCmdFlags.IncludeArchives is '-A'). Unfortunately it seems that '-e' is not supported by p4api.net.dll.

There is however a workaround using P4Command:

  var cmd = new P4Command(rep, "files", true);
  StringList args = new StringList(new[] { "-e", "//depot/....cpp" });
  P4CommandResult result = cmd.Run(args);

  IEnumerable<FileSpec> foundFiles =
    result.TaggedOutput.Select(o => 
      new FileSpec(new DepotPath(o["depotFile"]),
                   null,
                   null,
                   VersionSpec.None));

  foreach (FileSpec file in foundFiles)
    Console.WriteLine("Found {0}", file.DepotPath);

I'm using p4net.api.dll version 2013.3.78.1524.