Search code examples
winapitxf

How to determine if directory was created in current transaction?


I have some file/directory managment tool based on TxF system. Basically it's working like this:

  1. I'm creating transaction using CreateTransaction function.
  2. Somewhere later in the code I'm creating many directories using CreateDirectoryTransacted function.
  3. Later I need to determine if I already created directory from point (2) in given path being still in this transaction (no CommitTransaction called so far).

Is there some substitute to PathFileExists but working with transaction system?


Solution

  • I've managed to resolve this problem using CreateDirectoryTransacted and error code ERROR_ALREADY_EXISTS.

    Here is how:
    CreateDirectoryTransacted returns different error codes, one of them is ERROR_ALREADY_EXISTS. I can use this specific error to determine if directory already exists. If it does not, and I just created it there is nothing to worry about - I can safely remove it in the same transaction using RemoveDirectoryTransacted. I'm aware there will be some minor overhead if a lot of create->remove directory happen, but it's just not my case. It's just how I get around this problem.

    If somebody have idea for a better solution - I'm open to change correct answear to some more general solution.