Beispiel #1
0
KernelTransaction::KernelTransaction(){
	this->tx = CreateTransaction(nullptr, 0, 0, 0, 0, 0, nullptr);
	if (this->tx == INVALID_HANDLE_VALUE){
		auto error = GetLastError();
		throw Win32Exception(error);
	}
}
int __cdecl wmain(int argc, WCHAR* argv[])
{
    HRESULT hr = E_FAIL;
    
    ITransaction* pITransaction = NULL;
    HANDLE hTransactionHandle = INVALID_HANDLE_VALUE;

    // Parse the command line to see if -abort switch is used or not.
    // If the abort switch is used the transaction will be aborted at the end,
    // otherwise it will be committed.
    ParseCommandLine(argc, argv);

    // Get a pointer to a new transaction
    hr = CreateTransaction(&pITransaction);
    if (FAILED(hr)) 
        goto cleanup;

    // Get a transaction handle to use with the transacted file operation
    hr = GetKernelTransactionHandle(pITransaction, &hTransactionHandle);
    if (FAILED(hr)) 
        goto cleanup;

    // Do a transacted file operation
    hr = TransactedFileOperation(hTransactionHandle);
    if (FAILED(hr)) 
        goto cleanup;


    //-------------------------------------------------------------------------
    // Here you can do other operations to various Resource Managers as part 
    // of this transaction using the same ITransaction.
    //-------------------------------------------------------------------------


    // Commit or abort the transaction depending on the g_fAbort boolean variable
    // which was set by using the -abort command line parameter
    hr = CommitOrAbortTransaction(pITransaction);
    if (FAILED(hr)) 
        goto cleanup;

cleanup:
    
    if(INVALID_HANDLE_VALUE != hTransactionHandle)
    {
        CloseHandle(hTransactionHandle);
        hTransactionHandle = INVALID_HANDLE_VALUE;
    }
    
    if(NULL != pITransaction)
    {
        pITransaction->Release();
        pITransaction = NULL;
    }

    return 0;
}
Beispiel #3
0
///////////////////////////////////////////////////////////////////////////////
/// \brief
/// Initialize the repository manager.
///
void MgRepositoryManager::Initialize(bool transacted)
{
    AbortTransaction();

    m_transacted = transacted;

    if (m_transacted)
    {
        CreateTransaction();
    }
}
Beispiel #4
0
struct Transaction *AddTransactionImpl(MESSAGE *message, struct TransactionUser *user, int type)
{
    if (type == TRANSACTION_TYPE_SERVER_NON_INVITE) {
        if (!ValidatedNonInviteMethod(message)) return NULL;
    }

    struct Transaction *t = CreateTransaction(message, user, type);
    _AddTransaction(t);
    RunFsm(t, TRANSACTION_EVENT_INIT);
    
    return t;

}
void* os_start_transaction()
{
#ifdef USE_NTFS_TXF
	HANDLE htrans = CreateTransaction(NULL, NULL, 0, 0, 0, 0, NULL);
	if(htrans==INVALID_HANDLE_VALUE)
	{
		Log("Creating transaction failed. ec="+convert((int)GetLastError()), LL_WARNING);
		return NULL;
	}
	return htrans;
#else
	return NULL;
#endif
}
Beispiel #6
0
LSTATUS UpdateFile(CString lpExistingFileName, CString lpNewFileName)
{
	if (GetFileType(lpNewFileName) != PathIsDir)
	{
		return ERROR_FILE_NOT_FOUND;
	}

	LSTATUS lStatus = ERROR_FILE_NOT_FOUND;
	CString NewFile, OldFile;

	WIN32_FIND_DATAW FindFileData = {};
	HANDLE hFindFile = FindFirstFileW(lpNewFileName + L"*", &FindFileData);
	FILE_INTERNAL_INFORMATION IdNew, IdOld;

	if (hFindFile != INVALID_HANDLE_VALUE)
	{
		do
		{
			if (FindFileData.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)
			{
				if (_IsDots(FindFileData.cFileName) == 0)
				{
					auto lStatusTmp = UpdateFile(lpExistingFileName + FindFileData.cFileName + L"\\", lpNewFileName + FindFileData.cFileName + L"\\");
					if (lStatusTmp)
					{
						lStatus = lStatusTmp;
					}
				}
			}
			else
			{
				//TempFile = TempPath + FindFileData.cFileName;


				OldFile = lpExistingFileName + FindFileData.cFileName;
				NewFile = lpNewFileName + FindFileData.cFileName;


				////////////////////////////////////////
				//先检查文件是否为同一个文件
				if (auto Status = GetFileId(NewFile, NULL, &IdNew))
				{
					lStatus = RtlNtStatusToDosError(Status);
					continue;
				}

				if (auto Status = GetFileId(OldFile, NULL, &IdOld))
				{
					lStatus = RtlNtStatusToDosError(Status);
					continue;
				}

				if (IdNew.IndexNumber.QuadPart != IdOld.IndexNumber.QuadPart)
				{
					if (DirectGetOsMinVersion() >= MakeMiniVersion(6, 1))
					{
						if (!MoveFileEx(NewFile, OldFile, MOVEFILE_CREATE_HARDLINK | MOVEFILE_REPLACE_EXISTING))
						{
							lStatus = GetLastError_s();
						}
					}
					else
					{
						//Vista不支持直接替换,在Host为Vista时则使用事物处理来保证操作原子性
						auto hTransaction = CreateTransaction(NULL, 0, 0, 0, 0, INFINITE, nullptr);
						if (hTransaction == INVALID_HANDLE_VALUE)
						{
							lStatus = GetLastError_s();
						}
						else
						{
							if (DeleteFileTransactedW(OldFile, hTransaction)==FALSE || CreateHardLinkTransactedW(OldFile, NewFile,nullptr, hTransaction)==FALSE)
							{
								lStatus = GetLastError_s();
							}
							else
							{
								if (!CommitTransactionAsync(hTransaction))
								{
									lStatus = GetLastError_s();
								}
							}
							CloseHandle(hTransaction);
						}

					}
				}
			}




		} while (FindNextFile(hFindFile, &FindFileData));


		FindClose(hFindFile);
	}

	return lStatus;
}