2 * Copyright 2013, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
5 #ifndef FS_TRANSACTION_H
6 #define FS_TRANSACTION_H
17 typedef FSUtils::Entry Entry
;
20 class CreateOperation
;
21 class RemoveOperation
;
30 int32
CreateEntry(const Entry
& entry
,
31 int32 modifiedOperation
= -1);
32 int32
RemoveEntry(const Entry
& entry
,
33 const Entry
& backupEntry
,
34 int32 modifiedOperation
= -1);
35 int32
MoveEntry(const Entry
& fromEntry
,
37 int32 modifiedOperation
= -1);
39 void RemoveOperationAt(int32 index
);
43 typedef std::vector
<OperationInfo
> OperationList
;
46 static std::string
_GetPath(const Entry
& entry
);
49 OperationList fOperations
;
53 class FSTransaction::Operation
{
55 Operation(FSTransaction
* transaction
, int32 operation
)
57 fTransaction(transaction
),
58 fOperation(operation
),
65 if (fTransaction
!= NULL
&& fOperation
>= 0 && !fIsFinished
)
66 fTransaction
->RemoveOperationAt(fOperation
);
69 /*! Arms the operation rollback, i.e. rolling back the transaction will
70 revert this operation.
77 /*! Unregisters the operation rollback, i.e. rolling back the transaction
78 will not revert this operation.
82 if (fTransaction
!= NULL
&& fOperation
>= 0) {
83 fTransaction
->RemoveOperationAt(fOperation
);
91 FSTransaction
* fTransaction
;
97 class FSTransaction::CreateOperation
: public FSTransaction::Operation
{
99 CreateOperation(FSTransaction
* transaction
, const Entry
& entry
,
100 int32 modifiedOperation
= -1)
102 Operation(transaction
,
103 transaction
->CreateEntry(entry
, modifiedOperation
))
109 class FSTransaction::RemoveOperation
: public FSTransaction::Operation
{
111 RemoveOperation(FSTransaction
* transaction
, const Entry
& entry
,
112 const Entry
& backupEntry
, int32 modifiedOperation
= -1)
114 Operation(transaction
,
115 transaction
->RemoveEntry(entry
, backupEntry
, modifiedOperation
))
121 class FSTransaction::MoveOperation
: public FSTransaction::Operation
{
123 MoveOperation(FSTransaction
* transaction
, const Entry
& fromEntry
,
124 const Entry
& toEntry
, int32 modifiedOperation
= -1)
126 Operation(transaction
,
127 transaction
->MoveEntry(fromEntry
, toEntry
, modifiedOperation
))
133 #endif // FS_TRANSACTION_H