Jump to content


C++ API / How to get state of deleted file

API C++ deleted state

  • Please log in to reply
4 replies to this topic

#1 mazay

mazay

    Newbie

  • Members
  • Pip
  • 8 posts

Posted 26 October 2018 - 07:25 PM

Hi,

I'm currently working on a program in C++ using the latest API.

My problem starts when I delete a file using the program. If I create a new file at the same place with the same name, the file will be "marked for delete" or "deleted at HEAD revision".

I'm trying to add a check when I add the file to prevent this. But I can't find a way to get the state of the file since the file is no longer in the folder! How can I check, using the API, if the file is "marked for delete" or "deleted at HEAD revision"?

Thank you very much!

#2 Sambwise

Sambwise

    Advanced Member

  • Members
  • PipPipPip
  • 640 posts

Posted 27 October 2018 - 09:46 PM

Quote

My problem starts when I delete a file using the program. If I create a new file at the same place with the same name, the file will be "marked for delete" or "deleted at HEAD revision".

How do you "delete the file" and "create a new file" in the context of the program?  Simply deleting/creating a file on your local filesystem won't change its state in Perforce, so you're clearly running some Perforce commands, but you don't say which ones.

Quote

How can I check, using the API, if the file is "marked for delete" or "deleted at HEAD revision"?

To see if a file is open and for what action, you can use "p4 opened".
To see what the head revision of a file is, you can use "p4 files".

You can also use "p4 fstat" which bundles together a whole bunch of information (including those two pieces).

#3 mazay

mazay

    Newbie

  • Members
  • Pip
  • 8 posts

Posted 29 October 2018 - 03:11 PM

Thanks for your help

I use the method ClientAPI::Run() for every command. For example, when I delete a file, I use ClientAPI::Run("delete", ClientUser). My problem is that if I run ClientAPI::Run(fstat, ClientUser), The method only returns a success or fail and no information about the files. How can I access the information using ClientAPI::Run()?

#4 Sambwise

Sambwise

    Advanced Member

  • Members
  • PipPipPip
  • 640 posts

Posted 29 October 2018 - 05:36 PM

To handle output you need to implement the Output* handlers in your ClientUser subclass.  Most output will be returned via either ClientUser::Message() (which handles an Error message object -- for legacy reasons these are called "Error"s but they can actually represent any kind of human-readable message) or ClientUser::OutputStat() (which handles a StrDict dictionary object).

To get an idea of what these output objects look like, run commands at the command line with the global flags "-e" (to see Error info) or "-Ztag" (to see "tagged" StrDicts).  Note that "p4 fstat" is a special case and always runs in "tagged" mode rather than returning a human-readable message.

#5 mazay

mazay

    Newbie

  • Members
  • Pip
  • 8 posts

Posted 30 October 2018 - 07:55 PM

Thanks, that answered my question





Also tagged with one or more of these keywords: API, C++, deleted, state

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users