Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

133 lines
2.3 KiB

  1. /*++
  2. Copyright (C) 2000-2001 Microsoft Corporation
  3. --*/
  4. #include "precomp.h"
  5. #include <wbemcomn.h>
  6. #include <reposit.h>
  7. #include "filecach.h"
  8. #include "creposit.h"
  9. long CFileCache::InnerInitialize(LPCWSTR wszBaseName)
  10. {
  11. long lRes;
  12. StringCchCopyW(m_wszBaseName, MAX_PATH+1, wszBaseName);
  13. StringCchCatW(m_wszBaseName, MAX_PATH+1, L"\\");
  14. m_dwBaseNameLen = wcslen(m_wszBaseName);
  15. lRes = m_TransactionManager.Init();
  16. if(lRes != ERROR_SUCCESS)
  17. return lRes;
  18. lRes = m_TransactionManager.BeginTrans();
  19. if (lRes != ERROR_SUCCESS)
  20. {
  21. Clear(0);
  22. return lRes;
  23. }
  24. lRes = m_ObjectHeap.Initialize(&m_TransactionManager,
  25. (WCHAR*)wszBaseName,
  26. m_dwBaseNameLen);
  27. if(lRes != ERROR_SUCCESS)
  28. {
  29. m_TransactionManager.RollbackTrans();
  30. Clear(0);
  31. }
  32. else
  33. {
  34. lRes = m_TransactionManager.CommitTrans();
  35. if (lRes != ERROR_SUCCESS)
  36. {
  37. m_TransactionManager.RollbackTrans();
  38. Clear(0);
  39. }
  40. }
  41. return lRes;
  42. }
  43. long CFileCache::RepositoryExists(LPCWSTR wszBaseName)
  44. {
  45. CFileName wszStagingName;
  46. if (wszStagingName == NULL)
  47. return ERROR_OUTOFMEMORY;
  48. StringCchPrintfW(wszStagingName, wszStagingName.Length(), L"%s\\index.btr", wszBaseName);
  49. DWORD dwAttributes = GetFileAttributesW(wszStagingName);
  50. if (dwAttributes == -1)
  51. return ERROR_FILE_NOT_FOUND;
  52. return ERROR_SUCCESS;
  53. }
  54. long CFileCache::Initialize(LPCWSTR wszBaseName)
  55. {
  56. long lRes;
  57. if (m_bInit)
  58. return ERROR_SUCCESS;
  59. lRes = RepositoryExists(wszBaseName);
  60. if (ERROR_FILE_NOT_FOUND == lRes)
  61. {
  62. //If we have a database restore to do, go ahead and do it...
  63. lRes = DoAutoDatabaseRestore();
  64. }
  65. //
  66. // Initialize file cache. It will read the registry itself to find out
  67. // its size limitations
  68. //
  69. if (SUCCEEDED(lRes))
  70. {
  71. lRes = InnerInitialize(wszBaseName);
  72. if (ERROR_SUCCESS == lRes)
  73. {
  74. m_bInit = TRUE;
  75. }
  76. }
  77. return lRes;
  78. }
  79. CFileCache::CFileCache()
  80. : m_lRef(1), m_bInit(FALSE)
  81. {
  82. }
  83. CFileCache::~CFileCache()
  84. {
  85. }
  86. long CFileCache::Uninitialize(DWORD dwShutDownFlags)
  87. {
  88. if (!m_bInit)
  89. return 0;
  90. Clear(dwShutDownFlags);
  91. m_bInit = FALSE;
  92. return 0;
  93. }